1:下载工具包
登录网站下载相应的工具包
2:安装
(1)yum安装:
sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
yum list | grep percona-toolkit

结果集显示以下证明安装成功:

percona-toolkit.noarch 3.0.0-rc percona-release-noarch

然后进行安装

sudo yum install percona-toolkit

(2)解压安装包:

[root@localhost home]# cd toolkit/
[root@localhost toolkit]# ls
percona-toolkit-2.2.19.tar.gz
[root@localhost toolkit]# tar -xvf percona-toolkit.tar.gz

至此来说已经安装了percona 的toolKit工具包,下面主要测一下pt-table-checksum校验与pt-table-sync,前者主要用于数据的校验,验证主从是否一致,后者主要用来修复数据,两者一般情况结合起来用可以修复数据不一致的问题。

pt-table-checksum是percona公司提供的一款验证主从数据一致性的工具,我们指向主库,判断从库的结果集会反馈给我们,当有捕获到不一致问题的时候,就会返回一个非0的结果。但是他只能查找数据的不一致,如果要修复数据问题就要使用pt-table-sync。
pt-table-checksum在运行的时候是基于statement复制格式的,如果我们是ROW格式,需要在执行的时候加上--no-check-binlog-format参数。
3:pt-table-checksum的实践,装完以后我们就可以直接使用了,我这是使用的是第二种方式
[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format h=172.16.16.35,u=root,p=123456,P=3306
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
06-07T10:55:49 0 0 1 1 0 1.331 MAXIANGQIAN.MAXIANGQIAN
06-07T10:55:54 0 0 1 1 0 5.524 maxiangqian.test
06-07T10:55:56 0 0 4 1 0 1.208 maxiangqian.test01
06-07T10:55:57 0 0 0 1 0 1.164 mysql.columns_priv
06-07T10:55:58 0 0 5 1 0 1.216 mysql.db
06-07T10:55:59 0 0 2 1 0 1.176 mysql.engine_cost
06-07T10:56:00 0 0 0 1 0 1.178 mysql.event
06-07T10:56:01 0 0 0 1 0 1.160 mysql.func
06-07T10:56:03 0 0 1 1 0 1.154 mysql.gtid_executed
06-07T10:56:08 0 0 40 4 0 5.015 mysql.help_category
06-07T10:56:13 0 0 679 5 0 5.806 mysql.help_keyword
06-07T10:56:18 0 0 1334 4 0 4.572 mysql.help_relation
06-07T10:56:19 0 0 635 1 0 1.169 mysql.help_topic
06-07T10:56:20 0 0 0 1 0 1.163 mysql.ndb_binlog_index
06-07T10:56:22 0 0 0 1 0 1.157 mysql.plugin
06-07T10:56:23 0 1 48 1 0 1.236 mysql.proc
06-07T10:56:24 0 0 0 1 0 1.197 mysql.procs_priv
06-07T10:56:25 0 0 1 1 0 1.235 mysql.proxies_priv
06-07T10:56:26 0 0 6 1 0 1.188 mysql.server_cost
06-07T10:56:28 0 0 0 1 0 1.154 mysql.servers
06-07T10:56:34 0 0 1 1 0 6.184 mysql.tables_priv
06-07T10:56:35 0 0 0 1 0 1.198 mysql.time_zone
06-07T10:56:36 0 0 0 1 0 1.121 mysql.time_zone_leap_second
06-07T10:56:37 0 0 0 1 0 1.148 mysql.time_zone_name
06-07T10:56:38 0 0 0 1 0 1.147 mysql.time_zone_transition
06-07T10:56:40 0 0 0 1 0 1.138 mysql.time_zone_transition_type
06-07T10:56:41 0 0 8 1 0 1.336 mysql.user
06-07T10:56:42 0 0 0 1 0 1.164 open_api.ma
06-07T10:57:01 0 0 1000000 13 0 18.707 sbtest.sbtest
06-07T10:57:02 0 0 6 1 0 1.263 sys.sys_config

我们也可以单独检查某一个库,这样来缩小检查范围:

[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format --databases=maxiangqian h=172.16.16.35,u=root,p=123456,P=3306

得到的结果如上,看一下描述:

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 :端口

通过指定--replicate=rep_test.checksums 参数,会自动生成一个数据库.把检查信息都写到了checksums表中。

进入SLAVE相应的库中查看checksums表的信息,可以通过以下语句查看不一致的信息:
mysql> select * from checksums where this_cnt<>master_cnt;

通过上面的 this_crc <> master_crc 更能清楚的看出他们的不一致了,通过chunk知道是这个张表的哪个块上的记录出现不一致。

4:检测数据不一致的情况使用pt-table-sync进行修复
我们看一下上一节我们通过以下的语句检测到有数据是不一致的:
[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format --databases=maxiangqian h=172.16.16.35,u=root,p=123456,P=3306
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
06-07T11:13:18 0 0 1 1 0 1.220 MAXIANGQIAN.MAXIANGQIAN
06-07T11:13:19 0 1 1 1 0 1.135 maxiangqian.test
06-07T11:13:21 0 0 4 1 0 1.197 maxiangqian.test01

恢复不一致数据:

[root@localhost bin]# clear
[root@localhost bin]# ./pt-table-sync --execute h=172.16.16.35,P=3306,D=maxiangqian,t=test,u=root,p=123456 h=172.16.16.34,P=3306,u=root,p=123456 --no-check-slave --print
[root@localhost bin]# /home/toolkit/percona-toolkit-2.2.19/bin/pt-table-checksum --nocheck-replication-filters --replicate=rep_test.checksums --no-check-binlog-format --databases=maxiangqian h=172.16.16.35,u=root,p=123456,P=3306
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
06-07T11:18:09 0 0 1 1 0 1.172 MAXIANGQIAN.MAXIANGQIAN
06-07T11:18:10 0 0 1 1 0 1.144 maxiangqian.test
06-07T11:18:11 0 0 4 1 0 1.282 maxiangqian.test01

本身来说test这张表少了一行数据,执行以后主体和副本的数据将会一致:

接下来我们再看一下看一下pt-table-sync的一些使用案例:
(1)将host1上的数据同步到host2,只同步db.tbl表
pt-table-sync --execute h=host1,D=db,t=tbl h=host2
[root@localhost bin]# ./pt-table-sync --execute h=172.16.16.35,P=3306,D=maxiangqian,t=test,u=root,p=123456 h=172.16.16.34,P=3306,u=root,p=123456 --no-check-slave --print

(2)将host1 上的所有数据同步到host2和host3

pt-table-sync --execute host1 host2 host3
[root@localhost bin]# ./pt-table-sync --execute h=172.16.16.35,P=3306,D=maxiangqian,t=test,u=root,p=123456 h=172.16.16.34,P=3306,u=root,p=123456 h=172.16.16.35,P=3307,u=root,p=123456 --no-check-slave --print

(3)确保slave1上的所有数据和主库是同步的

pt-table-sync --execute --sync-to-master slave1
[root@localhost bin]# ./pt-table-sync --execute --sync-to-master h=172.16.16.34,P=3306,u=root,p=123456 --no-check-slave --print

这个要求所检查的表是必须有主键或者说唯一索引的。我们也可以按照下面指定单库的单表

[root@localhost bin]# ./pt-table-sync --execute --sync-to-master h=172.16.16.34,P=3306,D=maxiangqian,t=test01,u=root,p=123456 --no-check-slave --print

(4)按照检查生成的rep_test.checksums恢复所有的从库

pt-table-sync --execute --replicate test.checksum master1

也就是下面的例子:

[root@localhost bin]# ./pt-table-sync --execute --replicate rep_test.checksums h=172.16.16.35,P=3306,u=root,p=123456

(5)只修复slave1的数据

/pt-table-sync --execute --replicate rep_test.checksums --sync-to-master slave1

(6)双主模式master2修复自身数据:

pt-table-sync --execute --sync-to-master h=master2,D=db,t=tbl

由于双主模式有很多问题,一个修改可能会传给另外的数据库,所以说我们千万不能在双主的模式下执行以下的操作:

pt-table-sync --execute h=master1,D=db,t=tbl master2

pt-table-checksum校验与pt-table-sync修复数据的更多相关文章

  1. NXP ARM Vector Table CheckSum

    Signature Creator for NXP Cortex-M Devices Algorithm for creating the checksum The reserved Cortex-M ...

  2. Nodes “-1” are listed in ADOP_VALID_NODES table but not in FND_NODES table

    While trying to apply patches to upgrade to 12.2.4, adop failed due to the below errors. Validating ...

  3. Truncate table、Delete与Drop table的区别

    Truncate table.Delete与Drop table的区别 TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNC ...

  4. table完美css样式,table的基本样式,table样式

    table完美css样式,table的基本样式,table样式 >>>>>>>>>>>>>>>>> ...

  5. css实现鼠标移入table时出现滚动条且table内容不移位

    一般是这样: 表格的标题和内容分别由一个table组成,其中表格内容的table由一个class="table-body"的div包裹.css如下 .tContainer .tab ...

  6. 14.10.5 Reclaiming Disk Space with TRUNCATE TABLE 回收空间使用TRUNCATE TABLE

    14.10.5 Reclaiming Disk Space with TRUNCATE TABLE 回收空间使用TRUNCATE TABLE 回收操作系统磁盘空间当truncate 一个InnoDB ...

  7. ALTER TABLE SWITCH' statement failed. The table x' is partitioned while index 'x' is not partitioned.

    1.L_Monitoring有这么些字段,ID,Collecttime,PlateType,PlateNO以及其他一些这段.建立这个表的时候是个非分区表,其中ID是主键,并在Collecttime,P ...

  8. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -

    mysql -A不预读数据库信息(use dbname 更快)—Reading table information for completion of table and column names Y ...

  9. 解决:Reading table information for completion of table and column names

    mysql -A不预读数据库信息(use dbname 更快)—Reading table information for completion of table and column names Y ...

  10. Reading table information for completion of table and column names

    mysql> use ad_detail_page;Reading table information for completion of table and column namesYou c ...

随机推荐

  1. redis基础学习总结

    学习目标: 1.redis特点及安装     2.redis键值操作     3.redis数据类型[string, link,set,orderset,hash]     4.事务     5.消息 ...

  2. 如何把已有SQLSERVER数据库更名而且附加到数据库中?

    如何把已有SQLSERVER数据库更名而且附加到数据库中? 例如:已有数据库:zrmaa,希望更名为jjsh 特别提醒:数据库名中不能加入下划线,因为数据库日志文件有下划线. 把数据库文件mdf和数据 ...

  3. 为Linux技术学习推荐看的书籍—《Linux就该这么学》

    成长,是一种经历:经历,是一种人生的体验.人生的意义不在于我们拥有了什么,而在于从中我们体悟了什么.在这短短的三年,却在我的人生中弥足珍贵,在脑海中记忆犹新,在这大学三年里,我从一个莽撞少年成长为一名 ...

  4. vue+canvas踩坑之旅

    let img=new Image(); if(img.complete) { console.log('dd'); } img.src="http://localhost:8888/sta ...

  5. mybatis 使用IN 关键字

    mybatis 使用IN 关键字,查询条件如果有多个,拼接成字符串,当做参数传入的时候可能会只查询一条数据,那是因为mybits 将它当做一个字符串来处理了,这时候就需要使用<foreach&g ...

  6. FCC JS基础算法题(12):Where do I belong(数组排序并找出元素索引)

    题目描述: 先给数组排序,然后找到指定的值在数组的位置,最后返回位置对应的索引.举例:where([1,2,3,4], 1.5) 应该返回 1.因为1.5插入到数组[1,2,3,4]后变成[1,1.5 ...

  7. iOS动画学习

    学习一下动画,感谢以下大神的文章:    UIView:基础动画.关键帧动画.转场动画 Core Animation :基础动画,关键帧动画,动画组,转场动画,逐帧动画 CALayer :CALaye ...

  8. 《Java编程思想》读书笔记-对象导论

    计算机是头脑延伸的工具,是一种不同类型的表达媒体.本文以背景性的和补充性的材料,介绍包括开发方法概述在内的面向对象程序设计(Object-oriented Programming,OOP)的基本概念. ...

  9. MarkDown学习——基础用法

    目录 MarkDown开发版本MD2All基础用法 此处有代码<a id="top"></a>作为页内锚点 此处是用自动生成的目录 MarkDown是什么M ...

  10. java-ArrayList中去重复字符串或重复对象、LinkedList集合、泛型、增强for、静态导入、可变参数、asList()方法、集合嵌套

    1.去除ArrayList中重复字符串元素方式 * A:案例演示 * 需求:ArrayList去除集合中字符串的重复值(字符串的内容相同) * 思路:创建新集合方式 /** * A:案例演示 * 需求 ...