1. Introduction to master-slave replication
MySQL master-slave replication is to copy the data from one MySQL instance (master) to another MySQL real
Example (slave), and this replication is a process of asynchronous replication.
The entire replication operation is performed primarily by three processes, of which two processes are Slave (Sql_thread and
Io_thread), another process on the Master (IO process).
2. Principle and mechanism of master-slave copying
To implement replication, you must first turn on the binary log (Bin-log) function on the Master side, otherwise it cannot be implemented.
Because the entire replication process is actually Slave to get the log from the Master and then complete the sequence on the
Perform various actions that are logged in the log.
The basic process for replication is as follows:
1), Slave above the Io_thread connection on Master, and request from the specified log file at the specified location (or
Log contents from the beginning of the log);
2), Master receives the Io_thread request from Slave, through the IO process responsible for the replication according to please
The request information reads the log information after the specified log location, and returns the Io_thread to Slave. Returns information in addition to
The information contained in the log, including the information returned to the Master side of the Bin-log file, and
Bin-log POS;
3), Slave Io_thread received the message, the received log content is added to the Slave side of the
Relay-log the end of the file and logs the filename and location of the Bin-log read to the Master side to
Master-info file in order to be able to tell Master clearly at the next read, "I need a
Bin-log where to start the log content, please send me ";
4), Slave Sql_thread detected relay-log new additions to the content, will immediately parse Relay-log
Content becomes the executable content at the real execution time of the Master side and executes in this database.
3. master-slave copy schematic diagram
MySQL MySQL master-slave replication overview