[Database MySQL] Principle of master-slave replication

The basic principle of master-slave replication

1. MySQL records data changes to the binary log;

2. Slave writes the binary log of MySQL to the relay log of Slave;

3. Slave reads the relay log, parses the updated content into specific operations , and reflects it to its own (Slave) database.

 

The principle diagram of master-slave replication is as follows:

 

The detailed process of master-slave replication:

1. The I/O thread on the Slave side connects to the Master and requests the log content after the specified location of the specified log file (or the log from the very beginning) from the Master  ;

2. After the Master receives the request from the I/O thread of the Slave, the I/O thread responsible for copying reads the corresponding log content according to the request information of the Slave, returns it to the I/O thread of the Slave, and reads this request The name and location of the bin-log file taken are returned to the Slave end ;

3. After receiving the information, the I/O thread on the Slave side adds the received log content to the end of the relay-log (relay log) file on the Slave side, and reads the bin-log file on the Master side. The name and location are recorded in the master-info file, so that you can clearly tell the Master where to start sending the bin-log file ;

4. After the SQL thread on the Slave side detects the newly added content in the relay-log (relay log), it will immediately parse the relay-log content into the executable content when it is actually executed on the Master side, and execute it locally.

 

Guess you like

Origin blog.csdn.net/trichloromethane/article/details/113008212