使用 pt-table-checksum + pt-table-sync 检查并修复主从同步一致性问题。
第一步、使用 pt-table-checksum 检查
需要使用 –recursion-method 选项指定从库的连接方式,细节请参考官方文档。
检查所有数据库及表:
#!/bin/sh pt-table-checksum --recursion-method "xxx" --ask-pass 'h=127.0.0.1,P=3306,u=root'
检查特定数据库及表:
#!/bin/sh pt-table-checksum --recursion-method "xxx" --ask-pass --databases 'dbname' --tables='t1,t2' 'h=127.0.0.1,P=3306,u=root'
第二步、使用 pt-table-sync 处理
同步特定数据库及表:
#!/bin/sh pt-table-sync --execute --sync-to-master --ask-pass --databases 'dbname' --tables 't1' 'h=10.10.50.237,P=3306,u=root'
注意事项:建议使用 –dry-run 与 –print 选项查看将要执行的修改。
相关链接
Percona Toolkit/pt-table-checksum
Percona Toolkit/pt-table-sync