下载及用户赋权参考上篇文章percona-toolkit之pt-table-checksums检测Mysql主从数据一致性
先使用pt-table-checksums检测数据一致性,然后使用pt-table-sync进行主从一致性修复,注意修复的表必须有主键或者唯一索引
主库bash下执行:
./pt-table-checksum --nocheck-replication-filters --replicate=test.checksums --host=10.50.12.33 --port 3336 --databases=gaoquan -uchecksums -pchecksums --no-check-binlog-format --recursion-method=dsn=h=10.50.12.33,D=test,t=dsns
从库执行:
mysql> select * from checksums;
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
| db | tbl | chunk | chunk_time | chunk_index | lower_boundary | upper_boundary | this_crc | this_cnt | master_crc | master_cnt | ts |
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
| gaoquan | t1 | 1 | 0.001375 | NULL | NULL | NULL | afa2742d | 3 | 9cf2c2d4 | 4 | 2015-12-25 16:17:35 |
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
1 row in set (0.00 sec)
主库执行:
./pt-table-sync --execute --replicate test.checksums --sync-to-master h=10.50.12.35,P=3336,u=checksums,p=checksums
修复完毕后再使用pt-table-checksums进行主从一致性检测
主库执行:
./pt-table-checksum --nocheck-replication-filters --replicate=test.checksums --host=10.50.12.33 --port 3336 --databases=gaoquan -uchecksums -pchecksums --no-check-binlog-format --recursion-method=dsn=h=10.50.12.33,D=test,t=dsns
从库执行:
mysql> select * from checksums;
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
| db | tbl | chunk | chunk_time | chunk_index | lower_boundary | upper_boundary | this_crc | this_cnt | master_crc | master_cnt | ts |
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
| gaoquan | t1 | 1 | 0.0008 | NULL | NULL | NULL | 9cf2c2d4 | 4 | 9cf2c2d4 | 4 | 2015-12-28 11:44:53 |
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
1 row in set (0.00 sec)