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. 常用css属性记录

    CSS常用属性: 字体属性:(font)大小 font-size: x-large;(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD样式 font-style: ...

  2. 性能优化小Tips

    Performance Tips 这篇文章主要是介绍了一些小细节的优化技巧,当这些小技巧综合使用起来的时候,对于整个App的性能提升还是有作用的,只是不能较大幅度的提升性能而已.选择合适的算法与数据结 ...

  3. 缩短移动开发周期的ApiCloud

    ApiCloud百度百科介绍: ApiCloud 官网 官方论坛 APICloud经典O2O案例APP视频教程

  4. SQLite入门操作(一)

    //++其他的头文件 #include "sqlite3.h" #pragma comment(lib,"sqlite3.lib") int GetItemCo ...

  5. OLAP和数据挖掘的区别

    总结来说: 数据仓库提供了一个分析的数据源 数据挖掘能分析出未知的信息,提出假设 OLAP能通过分析,验证假设 从技术角度看,商务智能的过程是企业的决策人员以企业中的数据仓库为基础,经由数据挖掘工具. ...

  6. GridView的分页代码

    1.前台代码 <PagerTemplate><div style="text-align:center; color:Blue"> <asp:Link ...

  7. 通过bat设置系统环境变量

    在软件运行过程中,可能需要配置计算机的环境变量,在这里分为两种情况: 一:增加或修改环境变量只在当前软件环境中使用 如我们设置Java的环境变量: set CLASSPATH=%CLASSPATH%; ...

  8. python入门14 字典dict

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

  9. Android坡度计

    艺术来源于生活,对我来说,编程也是一门艺术.今天发布这篇技术博客,就是我跟朋友在一次爬山过程中的争论,他跟我说那座山至少45度,我说没有,最多30度.我们彼此争论不休,于是我就想,为啥不写个手机程序来 ...

  10. 用批处理在windows中导出/导入无线网络信息,复制保存为bat即可

    @echo offtitle 在windows中导出/导入无线网络信息 :Beginecho ========================echo 请选择操作:echo 1 查看可用的无线网络ec ...