MySQL master-slave synchronization problem is solved

Today, a piece of data was modified in the business system of the test environment and the database changed, but the data did not change when I queried it again. Even if I TRUNCATE all the database data, the data can still be found, which is very strange. The reason for positioning is: the update is in the main library, the query is in the slave library, and there is a problem with the replication between the master and the slave, which causes the modified data to not be displayed in time .
The solutions are as follows:

  1. First query the status of the master and slave libraries: show master status , show slave status ; found that the slave library Slave_SQL_Running: No, and the Last Error field: Error'Duplicate entry'xxxx' for key on table'.
  2. Then query the entry error line in the main library and the slave library respectively, and found that the main library does not exist, but the slave library exists, so the master-slave data is not synchronized, and the SQL thread does not work. Because the slave library has more data than the main library, so Suspected that the slave library can be written, so check the read-only status of the slave library, show variables like "%read_only%" ; found that the slave library is read-only, because the test environment and data are not very important, so the slave library will eventually have more data than the main library delete.
  3. Then restart the Slave. start slave; wait for the master-slave synchronization to complete, the problem is solved.

  4. Other query status SQL:

show variables like "%commit%";
show variables like "%sync%";

Guess you like

Origin blog.51cto.com/thinklili/2591474