Use mk-table-sync to summarize mk-table-sync? It is a powerful tool in maatkit for synchronizing master-slave databases. During synchronization, the DELETE, REPLACE, INSERT, UPDATE statements, mk-table-sync? Execute the statements that contain the preceding statements. for example, the master and slave databases have Table a. The data in the master database is as follows:
Id name
1 aa
2 bb
3 cc
4 dd
5 ee
6 ff
The data on the slave database is as follows:
Id name
1 aa
2 bb
3 hh
4 gg
5 ee
Mk-table-sync will execute three statements, synchronize "6 ff" to the slave database, update "3 cc", "4 gg" to the slave database, there are three statements in total, rather than the slave database that we see is only one less data entry than the master database. In fact, three statements are executed during the synchronization process;
Generally, the following synchronization operations are performed:
mk-table-sync --charset=utf8 --execute --print --no-check-slave -d test -t a /
h=localhost,u='root',p='123456' /
h=192.168.0.24,u='root',p='123456'
Note:
1. remember to add the -- charset option; otherwise, the slave database may be garbled;
2. if you want to see which data is not synchronized, you can do this:
mk-table-sync --charset=utf8 --print --no-check-slave -d test -t a /
h='127.0.0.1',u='root',p='123456' /
h='192.168.0.24',u='root',p='123456'>result
3. if there are several slave databases, we recommend that you synchronize them separately, unless the checksum of several slave databases is the same, because the synchronization steps of each slave database are not necessarily the same. if several slave databases are synchronized together, it is easy to cause primary key conflicts and lead to master-slave synchronization interruption. for example, we recommend that you:
mk-table-sync --charset=utf8 --execute --print --no-check-slave -d test -t a /
h='127.0.0.1',u='root',p='123456' /
h='192.168.0.24',u='root',p='123456'>result
Not recommended:
mk-table-sync --charset=utf8 --execute --print --no-check-slave -d test -t a /
h='127.0.0.1',u='root',p='123456' /
h='192.168.0.24',u='root',p='123456' /
h='192.168.0.25',u='root',p='123456' /
h='192.168.0.26',u='root',p='123456'>result
4. to reduce repeated operations, we can also synchronize several tables at a time, for example:
mk-table-sync --charset=utf8 --execute --print --no-check-slave -d test -t=a,b,c....