yum localinstall percona-toolkit-3.2.1-1.el7.x86_64.rpm
安裝依賴
yum install perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes perl -y
檢視相關命令
pt-table-checksum --help
192.168.8.112(主)
192.168.8.110(從)新增加一條資料
192.168.8.111(從)
目前主從不一致
[root@localhost data]
Checking if all tables can be checksummed ...
Starting checksum ...
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
12-06T15:46:35 0 1 8 7 1 0 0.108 mysqtest.runoob_tbl
DIFFS 0 表示一致 1表示不一致
列印 --print
pt-table-sync --sync-to-master h=192.168.8.110,u=qiao,p=root,P=3306 --databases=mysqtest --tables=runoob_tbl --print
執行 --execute
pt-table-sync --sync-to-master h=192.168.8.110,u=qiao,p=root,P=3306 --databases=mysqtest --tables=runoob_tbl --execute
[root@localhost data]
DELETE FROM `mysqtest`.`runoob_tbl` WHERE `runoob_id`='9' LIMIT 1 ;
Wide character in print at /usr/bin/pt-table-sync line 10965. while doing mysqtest.runoob_tbl on 192.168.8.110
建立恢復資料不一致shell指令碼
NUM=`pt-table-checksum --nocheck-replication-filters --replicate=check_data.checksums --no-check-binlog-format --databases=mysqtest --tables=runoob_tbl --user=qiao --password=root |
awk 'NR>1{sum+=$3}END{print sum}'`
if [ $NUM -eq 0 ] ; then
echo "Data is ok!"
else
echo "Data is error!"
pt-table-sync --sync-to-master h=192.168.8.110,u=qiao,p=root,P=3306 --databases=mysqtest --print
pt-table-sync --sync-to-master h=192.168.8.110,u=qiao,p=root,P=3306 --databases=mysqtest --execute
pt-table-sync --sync-to-master h=192.168.8.111,u=qiao,p=root,P=3306 --databases=mysqtest --print
pt-table-sync --sync-to-master h=192.168.8.111,u=qiao,p=root,P=3306 --databases=mysqtest --execute
fi
建立定時任務
* * * * * /home/pt-check-sync.sh
測試OK
本作品採用《CC 協議》,轉載必須註明作者和本文連結