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. 对 Vue 的理解(一)

    一.什么是 Vue ? 首先,Vue 是一个 MVVM 框架,M -- 模型,就是用来定义驱动的数据,V -- 视图,是经过数据改变后的 html,VM -- 框架视图,就是用来实现双向绑定的中间桥梁 ...

  2. IO流之递归

    递归: 递归,指在当前方法内调用自己的这种现象 public void method(){ System.out.println(“递归的演示”); //在当前方法内调用自己 method(); } ...

  3. Python爬虫《Python网络爬虫相关基础概念》

    引入 之前在授课过程中,好多同学都问过我这样的一个问题:为什么要学习爬虫,学习爬虫能够为我们以后的发展带来那些好处?其实学习爬虫的原因和为我们以后发展带来的好处都是显而易见的,无论是从实际的应用还是从 ...

  4. css控制文本单行或者多行溢出显示为省略号...

    p:first-child { background-color: pink; width: 150px; line-height: 28px; font-size: 20px; overflow: ...

  5. wx.grid 简单例子

    import wx, wx.grid class GridData(wx.grid.PyGridTableBase): _cols = "a b c".split() _data ...

  6. Azure 11 月新公布

    Azure 11 月新发布:Apple FairPlay Streaming, 应用服务(App Service), 虚拟机规模集(VMSS) Azure 媒体服务的 Apple FairPlay S ...

  7. 【Leetcode】【Easy】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  8. python入门14 字典dict

    字典dict是无序的key:value格式的数据序列 #coding:utf-8 #/usr/bin/python """ 2018-11-11 dinghanhua 字 ...

  9. Python:dict字典

    #字典dict------->唯一的映射类型 1.数据类型的划分 数据类型划分为可变数据类型和不可变数据类型. 不可变数据类型:tupe(元组).bool.int.str           可 ...

  10. 【洛谷P2657】[SCOI2009] windy数

    最近学习了一下数位DP 感觉记忆化搜索是比较好理解的 这篇博客对我有一定的启发https://www.cnblogs.com/zbtrs/p/6106783.html 总结了一下:    用数位DP的 ...