官方网站:https://www.percona.com/doc/percona-toolkit/2.1/pt-table-checksum.html#dsn-options
环境
主:10.50.12.33
从:10.50.12.35
****************************主从差异现象模拟****************************************
主:
mysql> create database gaoquan;
mysql> use gaoquan;
mysql> create table t1(id int PRIMARY KEY not null auto_increment,name varchar(10),age int);
mysql> insert into t1(name,age) values(‘a‘,32),(‘b‘,33),(‘c‘,34);
从:
mysql> use gaoquan
mysql> delete from t1 where name=‘a‘;
*****************************主从数据差异校验********************************************
主操作:
mysql -S /tmp/mysql3336.sock
######创建cheksums账号
mysql> GRANT SELECT, PROCESS, SUPER, REPLICATION SLAVE ON *.* TO ‘checksums‘@‘10.50.12.%‘ IDENTIFIED BY ‘checksums‘;
######创建从库信息表dsns
mysql> use test;
mysql> create table dsns(id int(11) not null auto_increment,parent_id int(11) default null,dsn varchar(255) not null,primary key(id));
######将从库信息插入dsns表中,多从就插入多条记录
mysql> INSERT INTO dsns (parent_id,dsn) values(1,‘h=10.50.12.35,u=checksums,p=checksums,P=3336‘);
######下载pt-tools工具
wget percona.com/get/percona-toolkit.tar.gz
tar -zxf percona-toolkit.tar.gz
cd percona-toolkit/bin
######执行校验
./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
######结果查询,this_crc != master_crc,说明主从数据有差异
mysql -h 10.50.12.35 -uchecksums -P3336 -p -e "select * from test.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 |
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+