Get the App
SLTechnology News&Howtos  ›  Database  › 

That's why! Why can we continue the master-slave replication relationship after performing stop slave and then start slave?

Shulou Source: shulou.com Published: 2022-06-01 14:30:12 09月27日 Update

Write it on the front:

We all know that Master is full of a binlog, or Master manually executes flush logs. SLave can continue to receive data from Master for synchronization without doing anything. I don't know if my friends have considered it. Why is this?

The reason is:

In fact, executing stop slave means closing the I/O thread (stop slave IO_THREAD) and SQL thread (stop slave SQL_THREAD) respectively. The I/O thread will maintain the update of master.info information, and the SQL thread will maintain the update of relay-log.info information. When executing start slave, I/O thread and SQL thread will continue to execute according to master.info and relay-log.info information, so replication can continue.

Here's a demonstration:

Execute on Master host:

mysql> show master status\G;

*************************** 1. row ***************************

File: mysql-bin.000008

Position: 120

Executed on Slave host

cat /home/data/mysql3306/master.info

mysql-bin.000008

120

192.168.32.3

Now manually scroll through the binlog log once in Master

mysql> flush logs;

mysql> show master status\G;

*************************** 1. row ***************************

File: mysql-bin.000009

Position: 120

Executed on Slave host

cat /home/data/mysql3306/master.info

23

mysql-bin.000009

120

192.168.32.3

As you can see, the Slave host copies Master's data exactly according to the master.info file.

Tags: Threads hosts information that is manual data updates reasons guys buddies files logs when this is synchronization presentation master and slave Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Redmi Microsoft Apple vpn