利用pt-table-checksum進行數據庫同步檢查
rpm方式#wget percona.com/get/percona-toolkit.rpm
源碼方式#wget http://www.percona.com/downloads/percona-toolkit/2.2.1/percona-toolkit-2.2.8.tar.gz
#yum install perl perl-CPAN perl-DBD-MySQL?perl-Time-HiRes
解壓,#perl Makefile.PL;make;make install
登陸slave和master(兩邊都要)
mysql>grant select,create,drop,delete,index,execute,super,process,replication slave on *.* to ptsum@'127.0.0.1' identified by 'ptchecksums';
mysql>grant select,create,drop,delete,index,execute,super,process,replication slave on *.* to ptsum@'master's IP' identified by 'ptchecksums';
mysql>grant select,create,drop,delete,index,execute,super,process,replication slave on *.* to ptsum@'slave's IP' identified by 'ptchecksums';
在新版本的pt-table-ckecksum不用自己添加checksums表,
#pt-table-checksum ?--nocheck-replication-filters --replicate=test.checksums --databases=a,b,c --no-check-binlog-format h=slave的IP,u=username,p=password,P=port
命令表示不檢查復制過濾器,把檢查結果寫到mysql中test庫中的checksums表,檢查的庫為a,b,c,不檢查binlog日志格式,并指定相關相信(地址,用戶名,密碼與商品)
如果binlog日志格式為row的話會報錯,通過上面--no-check-binlog-format來去除binlog日志檢查,以防報錯
此時如果提示Diffs cannot be detected because no slaves were found. ?Please read the --recursion-method documentation for information.
需要添加一個mysql路由記錄
登陸主庫
mysql>CREATE TABLE `test.dsns` ( `id` int(11) NOT NULL AUTO_INCREMENT,`parent_id` int(11) DEFAULT NULL,`dsn` varchar(255) NOT NULL,PRIMARY KEY (`id`));
mysql>use test
mysql>insert into dsns values(1,1,'h=slave的IP,u=username,p=password,P=3306');
在數據庫test中新建一張mysql的路由表,記錄slave連接方式,#pt-table-checksum ?--nocheck-replication-filters --replicate=test.checksums --databases=a,b,c --no-check-binlog-format h=master的ip,u=username,p=password,P=3306 --recursion-method dsn=D=test,t=dsns
命令表示:用。dsn方式進行檢查,D指上面存放mysql的路由表的庫,t是指表名
其中一些字段的說明
TS :完成檢查的時間。
ERRORS :檢查時候發生錯誤和警告的數量。
DIFFS :0表示一致,1表示不一致。當指定--no-replicate-check時,會一直為0,當指定--replicate-check-only會顯示不同的信息。
ROWS :表的行數。
CHUNKS :被劃分到表中的塊的數目。
SKIPPED :由于錯誤或警告或過大,則跳過塊的數目。
TIME :執行的時間。
TABLE :被檢查的表名。
--nocheck-replication-filters :不檢查復制過濾器,建議啟用。后面可以用--databases來指定需要檢查的數據庫。
--no-check-binlog-format : 不檢查復制的binlog模式,要是binlog模式是ROW,則會報錯。
--replicate-check-only :只顯示不同步的信息。
--replicate= :把checksum的信息寫入到指定表中,建議直接寫到被檢查的數據庫當中。
--databases= :指定需要被檢查的數據庫,多個則用逗號隔開。
--tables= :指定需要被檢查的表,多個用逗號隔開
h=127.0.0.1 :Master的地址
u=root :用戶名
p=123456 :密碼
P=3306 :端口
dsn=D :表示用dsn方式進行檢查,D為database
t=dsns :表示用這張表,
檢查同步后,可以用pt-table-sync進行同步,具體可以看下博客
http://www.cnblogs.com/2myroad/p/3842774.html