码迷,mamicode.com
首页 > 数据库 > 详细

pt-table-checksums监测Mysql主从数据一致性

时间:2015-12-25 19:30:49      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:pt-table-checksums

官方网站: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 |
+---------+-----+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+



pt-table-checksums监测Mysql主从数据一致性

标签:pt-table-checksums

原文地址:http://gaoquan.blog.51cto.com/4503718/1728339

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!