MySQL's master-slave is an asynchronous replication process, which is actually a process of copying data from the master to the slave end. The entire replication process between Master and Slave is performed primarily by three threads, of which two threads (SQL thread and I/O thread) are on the Slave side, and another thread (I/O thread) on the master side.
To achieve MySQL master-slave replication, you must first open the master side of the Binlog function, otherwise it will not be implemented. Because the entire replication process is actually a process that slave the logs from the master side and then executes the log in full sequence on its own. The Binlog method for opening MySQL is to add the "Log-bin" parameter entry under [Mysqld] in the MY.CNF configuration file.
The basic process for MySQL replication is as follows:
1. When master and slave establish the connection, first, the slave above the I/O thread through the Master-info file account and password to connect to master, after the connection is completed request master log file in the specified location and log content.
2. When Master receives a request from an I/O thread from Slave, the I/O thread responsible for replication reads the log information after the specified log specified location point according to the request information of the Slave side, and then returns the I/O thread to the Slave side. In addition to the information contained in the log, the returned information includes the name of the returned information in the Binlog file on the Master side and the location of the Binlog.
3. After the Slave I/O thread receives the information, the received log content is written to the end of the relay log (trunk log) file on the Slave side, and the file name and location of the read Binlog are recorded in the Master-info file. To be able to clearly tell the master "What I need from a binlog point in the log after the next read, please send me".
4. Slave's SQL thread detects that the newly added content in the Relay Log immediately resolves the query statement executed and executes the query itself. In this way, the same Query is actually executed on the Master and Slave ends, so the data on both ends is exactly the same.
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/8F/36/wKiom1jXuCTDHuhYAAFp3t3N7tw064.jpg-wh_500x0-wm_ 3-wmp_4-s_923101640.jpg "title=" master-slave copy schematic. jpg "alt=" wkiom1jxuctdhuhyaafp3t3n7tw064.jpg-wh_50 "/>
This article from the "12206254" blog, reproduced please contact the author!
MySQL master-slave replication principle