Mysql&Mariadb

MySQL主从数据一致性校验及修复

2017-12-30  本文已影响0人  显卡hg

主从为什么会不一致

什么时间要进行数据校验

pt-table-checksum

pt-table-checksum --nocheck-binlog-format --replication=xxx.checksums --ignore-databases=mysql --recursion-method=processlist --host=xxx --port=xxx --user=xxx 
 --password=xxx --databases=xxx
select db,tb1,SUM(this_cnt) AS total_rows,COUNT(*) AS chunks from wubx.checksum where (master_cnt <> this_cnt or master_crc <> this_crc or ISNULL(master_crc) <> ISNULL(this_crc)) group by db,tb1;

--nocheck-binlog-format的用途

指定库检测

pt-table-checksum --nocheck-binlog-format --replication=xxx.checksums  --recursion-method=processlist --host=xxx --port=xxx --user=xxx 
 --password=xxx --databases=xxx
 
 pt-table-checksum --nocheck-binlog-format --replication=xxx.checksums  --recursion-method=processlist --host=xxx --port=xxx --user=xxx 
 --password=xxx --ignore-databases=mysql

只显示不一致的

pt-table-checksum --nocheck-binlog-format --replication=xxx.checksums  --recursion-method=processlist --host=xxx --port=xxx --user=xxx 
 --password=xxx --databases=xxx --replicate-check-only

指定库和表来检查

pt-table-checksum --nocheck-binlog-format --replication=xxx.checksums  --recursion-method=processlist --host=xxx --port=xxx --user=xxx 
 --password=xxx --databases=xxx --tables=xxx

大的表分段检查(where条件的使用)

pt-table-checksum --nocheck-binlog-format --replication=xxx.checksums  --recursion-method=processlist --host=xxx --port=xxx --user=xxx 
 --password=xxx --databases=xxx --tables=xxx --where="id<=20000"

pt-table-sync

上一篇 下一篇

猜你喜欢

热点阅读