[mysql] mysql replication principle

(1) The master server records data changes in the binary log log. When the data on the master changes, the changes are written into the binary log; (2) The
slave server will detect the master binary log within a certain time interval. Whether it has changed. If it has changed, start an IIOThread to request the master binary event
(3). At the same time, the master node starts a dump thread for each /0 thread to send binary events to it and save it to the local memory of the slave node. In the relay log, the slave node will start the sQL thread to read the binary log from the relay log and replay it locally to make its data consistent with that of the master node. Finally, /OThread and SQLThread will enter the sleep state and wait for the next time they are awakened.
That is to say:
the slave library generates two threads, one 0 thread and one SQL thread; the
I/0 thread will request the binlog of the main library and write the obtained binlog to the local relay-log (relay log) file. ;
The main library will generate a Nog dump thread to transfer binlog to the slave library/O thread; the
SQL thread will read the logs in the relay log file and parse them into sql statements for execution one by one;
Note:
1--master will operate the statements Record to the binlog log, and then grant the slave remote connection permission (the master must enable the binlog binary log function; usually for data security considerations, the slave also enables the binlog function. 2- The slave opens two threads: 10 threads
and SQL threads. Among them :0 thread is responsible for reading the binlog content of the master into the relay log; the SQL thread is responsible for reading the binlog content from the relay log and updating it to the slave database, so as to ensure that the slave data and the master data are consistent .

Guess you like

Origin blog.csdn.net/David_Hzy/article/details/133322994