Summary using MK-table-sync

Source: Internet
Author: User

MK-table-sync is a powerful tool in maatkit for synchronizing master-slave databases. During synchronization, the delete, replace, insert, and update statements are synchronized, MK-table-sync executes all the preceding statements. For example, the master and slave databases contain 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....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.