MySQL主从验证技术01

学习目标:

了解熟悉pt-table-checksum 工具

pt-table-checksum缺点就是会遇到环境bug

工具下载:

DBI 下载地址:Index of /authors/id/T/TI/TIMB/

perl-DBD-MySQ下载地址:Index of /authors/id/C/CA/CAPTTOFU

或者我的博客资源进行下载:MySQL主从数据校验工具-MySQL文档类资源-CSDN下载

上传目录到/soft/


学习内容:

基于此博客环境做演示:MySQL基于GTID无损同步_零Ⅰ的博客-CSDN博客

1、解压安装DBI

tar -zxvf DBI-1.641.tar.gz

cd DBI-1.641

perl Makefile.PL

make

make test

make install

2、安装perl-DBD-MySQL     

先检查自己数据库里是否有这个安装包: rpm -qa |grep perl-DBD 

如果自己数据库中有,就不需要安装了,如果没有执行下列操作:

tar -zxvf DBD-mysql-4.046.tar.gz

cd DBD-mysql-4.046

perl Makefile.PL --mysql_config=/mysql/app/mysql/bin/mysql_config

make

make test

make install

 3、解压安装 percona-toolkit-3.0.8_x86_64.tar.gz

cd /soft

tar xvf percona-toolkit-3.0.8_x86_64.tar.gz

cd percona-toolkit-3.0.8

perl Makefile.PL

make && make install

cp /usr/local/bin/pt* /bin/

4、创建库和用户为当前写库

主库192.168.16.51:

mysql -uroot -proot

create database ptdb character set utf8;

create user 'checksums'@'192.168.16.%' identified by 'checksums';

grant update,insert,delete,select,process,lock tables,process,super,replication slave on *.* to 'checksums'@'192.168.16.%';

grant all on ptdb.* to 'checksums'@'192.168.16.%';

flush privileges;

5、在 master 主库上检查:

pt-table-checksum --defaults-file=/mysql/data/3306/my.cnf h=192.168.16.51,u=root,p=root,P=3306 --databases=00db --tables=yg --no-check-binlog-format --replicate=ptdb.checksums --nocheck-replication-filters

pt-table-checksum h=192.168.16.51,u=checksums,p='checksums',P=3306 --databases=00db --tables=yg --no-check-binlog-format --replicate=ptdb.checksums --nocheck-replication-filters

pt-table-checksum --defaults-file=/mysql/data/3306/my.cnf -h192.168.16.51 -P 3306 -u checksums -p checksums --no-check-binlog-format --replicate=ptdb.checksums --nocheck-replication-filters --databases itpuxdb --socket=/tmp/mysql.sock --recursion-method=hosts

从库可以执行本条 SQL 来查看哪些表有主从不一致的情况:

select db,tbl, sum(this_cnt) as total_rows, count(*) as chunks from ptdb.checksums where ( master_cnt <> this_cnt or master_crc <> this_crc or isnull(master_crc) <> isnull(this_crc)) group by db, tbl;

 

pt-table-checksum 常用案例:

例一:对特定表的一致性进行检查

pt-table-checksum --host='192.168.16.52' --user='root' --password='root' --port=3306 --recursion-method=processlist --replicate=percona.checksums --no-check-binlog-format --chunk-time=0.5 --tables='dbname.tb1,dbname2.tb2'

例二:对特定数据库的一致性进行检查

pt-table-checksum --host='192.168.16.52' --user='root' --password='root' --port=3306 --recursion-method=processlist --replicate=percona.checksums --no-check-binlog-format --chunk-time=0.5 --databases='dbname1,dbname2'

例三:对所有数据库的一致性进行检查

pt-table-checksum --host='192.168.16.52' --user='admin' --password='pwd' --port=3306 --recursion-method=processlist --replicate=percona.checksums --no-check-binlog-format --chunk-time=0.5

我自己虚拟机环境对pt-table-checksum工具不太友好,这里就不再一一验证,感兴趣的朋友,可以自己搞搞看

总结: 这个工具会有环境bug,有的环境使用没问题,有的环境就会遇到bug,生产上的环境不能随便更改,因为毕竟这个工具是开源的嘛,如果在自己的环境中使用没有bug,这个工具就可以用。如果自己的环境中无法使用此工具,可以选择使用Oracle官网出的mysqldiff工具。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值