percona工具pt-table-checksum

利用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
 
 

 

原文地址:https://www.cnblogs.com/2myroad/p/3837997.html