Preface
 
    We've used pt-table-checksum to checksum the different table data bwtween replication master and slaves yesterday.In this case,i'll use another of of Percona-Toolkit called "pt-table-sync" to sync these difference.These two instruments usually work together well in replication environment.Of course,pt-table-sync can be used independently,too.
 
Introduce
 
    pt-table-sync is a rather useful tool because replication is commonly implemented everywhere now.On account of replication delay or artificial error,slaves may turn out to be inconsistent with master.It will help use efficiently solving the problems.The machenism is to generate SQL statements and execute them on the specified servers.Let's see some details of it.
 
Procedure
 
Usage:
pt-table-sync [OPTIONS] DSN [DSN] --DSN format is key=value[,key=value...]

Parameters introduce:

###Connect parameters.###
-h hostname
-P port
-u username
-p password
-S socket ###Object Parameters.###
-d databases
-t tables ###Frequently-used parameters.###
--execute -- Really make changes happen accoridng to the SQL statments.
--replicate -- sync differences just depend on checksums table generated by pt-table-checksum tool.
--sync-to-master -- only used to specify one slave to sync differences with master.
--replace -- Turn all the inser & update statments into repalce. ###Output parameters.###
--verbose -- Show details of SQL statements.
--print -- Print all the relevent differences. ###Other parameters.###
--dry-run -- Don't really change data at all.

Generate the newest "checksums" table by pt-table-checksum on master.

 [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums -h192.168.1. -P3306 -urepl --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
-22T09:: 0.012 mysql.columns_priv
-22T09:: 0.015 mysql.db
-22T09:: 0.016 mysql.engine_cost
-22T09:: 0.016 mysql.event
-22T09:: 0.017 mysql.func
-22T09:: 0.015 mysql.help_category
-22T09:: 0.015 mysql.help_keyword
-22T09:: 0.017 mysql.help_relation
-22T09:: 0.022 mysql.help_topic
-22T09:: 0.015 mysql.ndb_binlog_index
-22T09:: 0.016 mysql.plugin
-22T09:: 0.018 mysql.proc
-22T09:: 0.014 mysql.procs_priv
-22T09:: 0.014 mysql.proxies_priv
-22T09:: 0.015 mysql.server_cost
-22T09:: 0.015 mysql.servers
-22T09:: 0.016 mysql.tables_priv
-22T09:: 0.016 mysql.time_zone
-22T09:: 0.018 mysql.time_zone_leap_second
-22T09:: 0.016 mysql.time_zone_name
-22T09:: 0.015 mysql.time_zone_transition
-22T09:: 0.016 mysql.time_zone_transition_type
-22T09:: 0.017 mysql.user
-22T09:: 0.016 sys.sys_config
-22T09:: 0.015 zlm.test_ddl
-22T09:: 0.015 zlm.test_ddl_no_pk
-22T09:: 0.016 zlm.test_innodb
-22T09:: 0.018 zlm.test_myisam

Check the details of differet tables on slave(master won't have these records).

 (root@localhost mysql3306.sock)[zlm]::>select db,tbl,chunk,chunk_time,this_crc,this_cnt,master_crc,master_cnt,ts from checksums where this_cnt<>master_cnt;
+---------+-----------+-------+------------+----------+----------+------------+------------+---------------------+
| db | tbl | chunk | chunk_time | this_crc | this_cnt | master_crc | master_cnt | ts |
+---------+-----------+-------+------------+----------+----------+------------+------------+---------------------+
| mysql | proc | | 0.001536 | 9e5a007c | | 4e0f05d9 | | -- :: |
| mysql | user | | 0.001122 | 7de55b47 | | 587dfc7 | | -- :: |
| percona | checksums | | 0.000952 | 22f7b633 | | d162e2ce | | -- :: |
+---------+-----------+-------+------------+----------+----------+------------+------------+---------------------+
rows in set (0.00 sec)

Sync table data by pt-table-sync(use both "replication"&"--sync-to-master").

 [root@zlm2 :: ~]
#pt-table-sync --execute --replicate zlm.checksums --print --sync-to-master h=192.168.1.102,P=,u=repl --ask-pass
Enter password for 192.168.1.102:
-- Omitted.

Check the differences again.

 [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums -h192.168.1. -P3306 -urepl --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
-22T10:: 0.014 mysql.columns_priv
-22T10:: 0.016 mysql.db
-22T10:: 0.018 mysql.engine_cost
-22T10:: 0.017 mysql.event
-22T10:: 0.017 mysql.func
-22T10:: 0.016 mysql.help_category
-22T10:: 0.018 mysql.help_keyword
-22T10:: 0.017 mysql.help_relation
-22T10:: 0.021 mysql.help_topic
-22T10:: 0.018 mysql.ndb_binlog_index
-22T10:: 0.016 mysql.plugin
-22T10:: 0.018 mysql.proc
-22T10:: 0.016 mysql.procs_priv
-22T10:: 0.016 mysql.proxies_priv
-22T10:: 0.014 mysql.server_cost
-22T10:: 0.014 mysql.servers
-22T10:: 0.016 mysql.tables_priv
-22T10:: 0.016 mysql.time_zone
-22T10:: 0.016 mysql.time_zone_leap_second
-22T10:: 0.016 mysql.time_zone_name
-22T10:: 0.016 mysql.time_zone_transition
-22T10:: 0.016 mysql.time_zone_transition_type
-22T10:: 0.016 mysql.user
-22T10:: 0.015 sys.sys_config
-22T10:: 0.015 zlm.test_ddl
-22T10:: 0.015 zlm.test_ddl_no_pk
-22T10:: 0.015 zlm.test_innodb
-22T10:: 0.015 zlm.test_myisam

Since no diffs above,there're no more informations when reexecute pt-table-sync.

 [root@zlm2 :: ~]
#pt-table-sync --execute --replicate zlm.checksums --print --verbose --sync-to-master h=192.168.1.102,P=,u=repl --ask-pass
Enter password for 192.168.1.102:
# Syncing via replication P=,h=192.168.1.102,p=...,u=repl
# DELETE REPLACE INSERT UPDATE ALGORITHM START END EXIT DATABASE.TABLE
Unknown database 'percona' [for Statement "USE `percona`"] at line while doing percona.checksums on 192.168.1.102
# :: :: percona.checksums

Make data difference again by modify one record.

 ###Check Master.###
(root@localhost mysql3306.sock)[zlm]::>select * from mysql.tables_priv;
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| localhost | mysql | mysql.session | user | boot@connecting host | -- :: | Select | |
| localhost | sys | mysql.sys | sys_config | root@localhost | -- :: | Select | |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
rows in set (0.00 sec) ###Modify slave.###
(root@localhost mysql3306.sock)[zlm]::>update mysql.tables_priv set timestamp='2018-06-20 08:00:00' where db='mysql';
Query OK, row affected (0.00 sec)
Rows matched: Changed: Warnings: (root@localhost mysql3306.sock)[zlm]::>select * from mysql.tables_priv;
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| localhost | mysql | mysql.session | user | boot@connecting host | -- :: | Select | |
| localhost | sys | mysql.sys | sys_config | root@localhost | -- :: | Select | |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[zlm]::>select * from mysql.tables_priv;
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| localhost | mysql | mysql.session | user | boot@connecting host | -- :: | Select | |
| localhost | sys | mysql.sys | sys_config | root@localhost | -- :: | Select | |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
rows in set (0.00 sec)

Check the differences again.

 [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums -h192.168.1. -P3306 -urepl --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
-22T10:: 0.012 mysql.columns_priv
-22T10:: 0.014 mysql.db
-22T10:: 0.014 mysql.engine_cost
-22T10:: 0.017 mysql.event
-22T10:: 0.014 mysql.func
-22T10:: 0.016 mysql.help_category
-22T10:: 0.016 mysql.help_keyword
-22T10:: 0.017 mysql.help_relation
-22T10:: 0.019 mysql.help_topic
-22T10:: 0.015 mysql.ndb_binlog_index
-22T10:: 0.013 mysql.plugin
-22T10:: 0.016 mysql.proc
-22T10:: 0.015 mysql.procs_priv
-22T10:: 0.015 mysql.proxies_priv
-22T10:: 0.015 mysql.server_cost
-22T10:: 0.015 mysql.servers
-22T10:: 0.014 mysql.tables_priv
-22T10:: 0.013 mysql.time_zone
-22T10:: 0.014 mysql.time_zone_leap_second
-22T10:: 0.018 mysql.time_zone_name
-22T10:: 0.016 mysql.time_zone_transition
-22T10:: 0.017 mysql.time_zone_transition_type
-22T10:: 0.017 mysql.user
-22T10:: 0.016 sys.sys_config
-22T10:: 0.017 zlm.test_ddl
-22T10:: 0.015 zlm.test_ddl_no_pk
-22T10:: 0.014 zlm.test_innodb
-22T10:: 0.016 zlm.test_myisam

Sync table data by pt-table-sync again(only use "--replication").

 [root@zlm2 :: ~]
#pt-table-sync --execute --replicate zlm.checksums --print --verbose h=192.168.1.101,P=,u=repl --ask-pass
Enter password for 192.168.1.101:
# Syncing via replication P=,h=zlm3,p=...,u=repl
# DELETE REPLACE INSERT UPDATE ALGORITHM START END EXIT DATABASE.TABLE
REPLACE INTO `mysql`.`tables_priv`(`host`, `db`, `user`, `table_name`, `grantor`, `timestamp`, `table_priv`, `column_priv`) VALUES ('localhost', 'sys', 'mysql.sys', 'sys_config', 'root@localhost', '2018-06-13 04:11:40', 'Select', '') /*percona-toolkit src_db:mysql src_tbl:tables_priv src_dsn:P=3306,h=192.168.1.101,p=...,u=repl dst_db:mysql dst_tbl:tables_priv dst_dsn:P=3306,h=zlm3,p=...,u=repl lock:1 transaction:0 changing_src:zlm.checksums replicate:zlm.checksums bidirectional:0 pid:4514 user:root host:zlm2*/;
# Nibble :: :: mysql.tables_priv
Unknown database 'percona' [for Statement "USE `percona`"] at line while doing percona.checksums on zlm3
# :: :: percona.checksums

Check the differences again.

 [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums -h192.168.1. -P3306 -urepl --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
-22T10:: 0.012 mysql.columns_priv
-22T10:: 0.016 mysql.db
-22T10:: 0.014 mysql.engine_cost
-22T10:: 0.014 mysql.event
-22T10:: 0.017 mysql.func
-22T10:: 0.017 mysql.help_category
-22T10:: 0.018 mysql.help_keyword
-22T10:: 0.017 mysql.help_relation
-22T10:: 0.020 mysql.help_topic
-22T10:: 0.018 mysql.ndb_binlog_index
-22T10:: 0.017 mysql.plugin
-22T10:: 0.017 mysql.proc
-22T10:: 0.016 mysql.procs_priv
-22T10:: 0.016 mysql.proxies_priv
-22T10:: 0.018 mysql.server_cost
-22T10:: 0.015 mysql.servers
-22T10:: 0.015 mysql.tables_priv
-22T10:: 0.015 mysql.time_zone
-22T10:: 0.017 mysql.time_zone_leap_second
-22T10:: 0.017 mysql.time_zone_name
-22T10:: 0.016 mysql.time_zone_transition
-22T10:: 0.015 mysql.time_zone_transition_type
-22T10:: 0.018 mysql.user
-22T10:: 0.015 sys.sys_config
-22T10:: 0.018 zlm.test_ddl
-22T10:: 0.016 zlm.test_ddl_no_pk
-22T10:: 0.016 zlm.test_innodb
-22T10:: 0.015 zlm.test_myisam

Check data in table on slave.

 (root@localhost mysql3306.sock)[zlm]::>select * from mysql.tables_priv;
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
| localhost | mysql | mysql.session | user | boot@connecting host | -- :: | Select | |
| localhost | sys | mysql.sys | sys_config | root@localhost | -- :: | Select | |
+-----------+-------+---------------+------------+----------------------+---------------------+------------+-------------+
rows in set (0.00 sec)
Summary
  • Take care of the DSN configuration while using diffrent parameter of pt-table-sync.
  • pt-table-sync can be used without pt-table-checksum either(don't specify "--replication" parameter,but need give DSN).
  • pt-table-sync requires statement-based replication while using "--replication" or "--sync-to-master".
  • The user of execute pt-table-sync need SUPER privilege to modify the "binlog_fomat"  variable to row.
  • pt-table-sync does not relies on primary key or unique key,but "--replace" parameter does.

Percona-Tookit工具包之pt-table-sync的更多相关文章

  1. Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程

    一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...

  2. Linux后台开发工具箱-葵花宝典

    Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...

  3. [知识库分享系列] 二、.NET(ASP.NET)

    最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...

  4. Linux后台开发工具箱

    https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...

  5. 推荐几款MySQL相关工具

    前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...

  6. SQL慢查询安装过程

    SQL慢查询 基本操作 打开防火墙 firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload 安 ...

  7. 【Oracle】OGG单向复制配置

    实验环境: 源端: Ip:192.168.40.10 DataBase:Oracle 11.2.0.1.0 ORCL OS:OEL5.6 OGG:fbo_ggs_Linux_x86_ora11g_32 ...

  8. regex & tab spaces

    regex & tab spaces txt file format let x = `2018-10-20a2018-10-20a2018-10-20a`; x.replace(/a/ig, ...

  9. PXC集群资料整理

    1.mysql集群方案对比 方案1  NDBCluster  参考:https://www.cnblogs.com/kevingrace/p/5685371.html?utm_source=itdad ...

  10. xtrabackup备份原理及流式备份应用

    目录 xtrabackup备份原理及流式备份应用 0. 参考文献 1. xtrabackup 安装 2. xtrabackup 备份和恢复原理 2.1 备份阶段(backup) 2.2 准备阶段(pr ...

随机推荐

  1. mysql五:pymysql模块

    一.介绍 之前都是通过MySQ自带的命令行客户端工具Mysql来操作数据库,那如何在Python程序中操作数据库呢?这就需要用到pymysql模块了. 这个模块本质就是一个套接字客户端软件,使用前需要 ...

  2. 原生js封装十字参考线插件(一)

    需求来源: 拓扑图之机房平面图,显示机房长宽比例尺,房间内标注各种设备间距不易实现,特在机房平面图上层加一个十字参考线 横竖两条线垂直,在鼠标指针处交叉,显示鼠标指针坐标(相对机房平面图的坐标,不是相 ...

  3. Eclipse SWT

    Reference: http://www.eclipse.org/swt/ http://www.functionx.com/win32/Lesson01.htm http://www.win32d ...

  4. 设计模式——工厂方法模式(Factory Method)

    原文地址:http://www.cnblogs.com/Bobby0322/p/4179921.html 介绍 在简单工厂模式中,我们提到,工厂方法模式是简单工厂模式的一个延伸,它属于Gof23中设计 ...

  5. C# WinForm 程序免安装 .NET Framework(XP/win7/win10环境运行)

    前文 首先感谢群里的大神宇内流云 提供的anyexec for windows版本. 经过本人搭建虚拟机在xp环境 使用anyexec运行winfrom程序后,测试通过,如下是用的xp运行winfro ...

  6. March 22 2017 Week 12 Wednesday

    Satisfaction doesn't come from the outside, but from the inside. 满足感并非来自外界,而是来自内心. Everything that e ...

  7. ZT 头文件包含其实是一想很烦琐的工作 第一个原则应该是,如果可以不包含头文件

    当出现访问类的函数或者需要确定类大小的时候,才需要用头文件(使用其类定义)    http://blog.csdn.net/clever101/article/details/4751717 看到这个 ...

  8. 转一个csdn看到的帖子:而立之年的程序猿失业了 [问题点数:0分,结帖人jinxingfeng_cn]

    http://bbs.csdn.net/topics/390612263?page=1#post-395768948

  9. python UI自动化实战记录一:测试需求与测试思路

    测试需求: 项目包含两个数据展示页面,数据均来自于四个数据源接口. 测试操作步骤: 选择5个大类型中的一个,每个大类型下有3个子类型,选择任一子类型,页面数据更新.需验证页面上的数据与数据源接口数据一 ...

  10. sparkStreamming原理

    一.Spark Streamming 是基于spark流式处理引擎,基本原理是将实时输入的数据以时间片(秒级)为单位进行拆分,然后经过spark引擎以类似批处理的方式处理每个时间片数据. 二.Spar ...