Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of MYSQL master inconsistency

Shulou Source: shulou.com Published: 2022-06-02 06:03:36 10月04日 Update

This article introduces how to solve MYSQL master-slave inconsistency, the content is very detailed, interested friends can refer to it, I hope it can help you.

Master-slave inconsistency in MYSQL is very likely to occur, and how to find inconsistency is not a very simple problem. Especially when the data volume is large. It is useless to talk nonsense. Look at the following example:

Let's start by creating a stored procedure to insert our initialization data

delimiter //

DROP PROCEDURE IF EXISTS insert_test_val;

##num_limit Number of data to insert,rand_limit Maximum random number

CREATE PROCEDURE insert_test_val()

BEGIN

DECLARE i int default 1;

DECLARE a varchar(20) ;

DECLARE b smallint ;

DECLARE c smallint ;

WHILE i /data/fix.sql

Import SQL after export in the associated library

Then go back to the main library, clean up the checksums table, and then execute the command again. Looking at the chekcsums table, you can clearly see that the values of each chunk are equal.

You can see that data that fixes differences is OK.

Just now, the data is different (missing data). If the data inside is not missing, just the value inside changes, will it be impossible to use this tool? The answer is impossible.

We can try changing the name value from the library

In the screenshot we changed the NAME value

We can clearly see from the command just now that the relevant modified records can be found and repaired.

So far, the PT tool to fix the master-slave inconsistency method is still very effective, but if most of your tables are inconsistent, it is recommended to do a master-slave copy more efficient.

MYSQL also provides a checksum table command that can quickly determine whether one table is different from another. Note that the use here is not the same, through the official text prompt two different tables is also possible to produce consistent values, of course, such a probability will be relatively low.

How to solve MYSQL master-slave inconsistency is shared here. I hope the above content can be of some help to everyone and learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Data consistency detection never command method or check run same content official tool suggestion database more missing procedure faceted storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei vpn MySQL Docker