Mysql master-slave replication - what to do if the slave server stops
You may find this topic a little ridiculous. What can we do if the server stops? Of course, we should restart the service. Restarting the service is no problem. The problem is that a lot of data has been written to the master database during the period when the slave server is stopped. How can we synchronize this data to the slave database?
If the master server is only updating data during the period when the slave server stops running, the slave I/O thread will be automatically started after the slave server starts the service to connect to the master server to request the update event of the binlog file. The Binlog dump thread of the master server will send the updated operation event to the Slave I/O thread, and the Slave I/O thread will write the received content to the relay log file. Then the Slave SQL thread will execute these events, thereby synchronizing the data.
Of course, there may be inconsistencies between the master_log_pos or master_log_file on the slave server and the master server.
Check the information from the server with the following command
mysql> show slave status\G
Check the information of the main server with the following command
mysql> show master status;
Then modify the information of connecting to the master server from the slave server by comparison. You can modify it with the following command
mysql> change master to master_log_pos=value,master_log_file=file
If the above situation goes smoothly, data can be synchronized in time. However, if during the period when the slave server stops running, the master server not only updates the data but also performs the following operations:
mysql> flush master;
This will initialize the bin log file on the master server, and all previous updates will disappear. In this case, simply enabling the service on the slave server or changing information such as master_log_pos will not help, and the data will not be synchronized in time. However, we need to reset the connection information of the slave server in time so that the data can be synchronized in time in the future.
mysql> stop slave;
mysql> reset slave;
mysql> start slave;
Through the above operations, the data updated after flushing the master server can be synchronized to the slave server. However, the previous data will be lost.
If you want to recover the lost data, you can back up the data on other normally operating slave servers and then import it to the current slave server, or directly back up the data on the master server.
All of the above is just one case. The specific problems that may occur during operation may be different for each person. But in general, no matter what the situation is, the solution should be centered around the bin log and the relay log on the slave server, as well as data backup. Therefore, good data backup is the best way to ensure that data will not be lost to the greatest extent.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Two ways to install mysql-5.5.47 on Linux system and manage mysql
Publish Date:2025/04/26 Views:140 Category:MySQL
-
We know that there are generally two ways to install software on the Linux system. One is to use rpm or yum to install, which is convenient and fast; the other is to use the compiled source package. Although this method is more troublesome
Mysql master-slave replication simple configuration
Publish Date:2025/04/26 Views:120 Category:MySQL
-
I'm learning about MySQL master-slave replication recently and want to apply it to a project at work. Since I'm new to it, I don't understand it very well, so I can only share how to make a simple configuration. At the beginning, we configu
Implementation details of MySQL master-slave replication (I) Exploration of the m
Publish Date:2025/04/26 Views:56 Category:MySQL
-
This article mainly discusses the implementation mechanism of master-slave replication, which may not be directly helpful for our actual application, but understanding its principle can achieve twice the result with half the effort for futu
Implementation details of MySQL master-slave replication (II) Exploration from th
Publish Date:2025/04/26 Views:74 Category:MySQL
-
Previously we explored the master server in master-slave replication. Now let's look at how the slave server works in the entire system. In the article Master Server Exploration, we mentioned that three threads are needed in a master-slave
How to back up a Kubernetes MySQL Operator cluster
Publish Date:2025/04/26 Views:79 Category:MySQL
-
Oracle's MySQL Operator for Kubernetes is a convenient way to automatically configure a MySQL database within a cluster. One of the key features of the Operator is the integrated automatic backup support for increased resiliency. The backup
How to select from multiple tables in MySQL
Publish Date:2025/04/25 Views:58 Category:MySQL
-
This article explains how to use MySQL to query from multiple tables in one script SELECT . Let's demonstrate a situation: SELECT name , price, details, type , FROM food, food_order WHERE breakfast.id = 'breakfast_id' Now, let's imagine FRO
Creating a table from CSV in MySQL
Publish Date:2025/04/25 Views:115 Category:MySQL
-
In this article, we aim to understand how to create a table from CSV in MySQL database. Businesses and organizations must quickly generate tables from large amounts of data. These organizations typically have large CSV files with large amou
Creating a Temporary Table in MySQL
Publish Date:2025/04/25 Views:183 Category:MySQL
-
In this article, we aim to explore different ways to create temporary tables in MySQL. One of the main features of temporary tables is that it helps in storing temporary data. This feature is enabled in MySQL 3.23 and later versions. These
Truncate all tables in Mysql
Publish Date:2025/04/25 Views:90 Category:MySQL
-
Today I will show you how to truncate all tables in Mysql. It is used when you want to delete the entire table TRUNCATE TABLE . TRUNCATE It is a type of DML statement, which means it cannot be rolled back once it is committed. There are two