Percona-Tookit工具包之pt-table-sync
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)
- 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的更多相关文章
- Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程
一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...
- Linux后台开发工具箱-葵花宝典
Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...
- [知识库分享系列] 二、.NET(ASP.NET)
最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...
- Linux后台开发工具箱
https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...
- 推荐几款MySQL相关工具
前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...
- SQL慢查询安装过程
SQL慢查询 基本操作 打开防火墙 firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload 安 ...
- 【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 ...
- regex & tab spaces
regex & tab spaces txt file format let x = `2018-10-20a2018-10-20a2018-10-20a`; x.replace(/a/ig, ...
- PXC集群资料整理
1.mysql集群方案对比 方案1 NDBCluster 参考:https://www.cnblogs.com/kevingrace/p/5685371.html?utm_source=itdad ...
- xtrabackup备份原理及流式备份应用
目录 xtrabackup备份原理及流式备份应用 0. 参考文献 1. xtrabackup 安装 2. xtrabackup 备份和恢复原理 2.1 备份阶段(backup) 2.2 准备阶段(pr ...
随机推荐
- 面试基础(二)-mem函数
常考的函数有下面三个,memset,memcpy,memmove,一定要记住三个函数的函数原型,熟记返回值类型和参数类型,当然也不能忘记参数检查 memset #include<iostre ...
- Nodejs中使用异步流程控制Async
首先,我们都知道,Node基于事件驱动的异步I/O架构,所谓异步就是非阻塞,说白了就是一个事件执行了,我不必等待它执行完成后我才能执行下一个事件.所以在Node环境中的模块基本都是异步的,上一篇说到我 ...
- The nineteenth day
Twinkle,twinkle,little start! 闪烁,闪烁,小星星 How I wonder what you are, 我想知道你是什么 Up above the world so hi ...
- Java入门到精通——调错篇之Spring2.5利用aspect实现AOP时报错: error at ::0 can't find referenced pointcut XXX
一.问题描述及原因. 利用Aspect注解实现AOP的时候出现了error at ::0 can't find referenced pointcut XXX.一看我以为注解写错了,结果通过查询相关资 ...
- IntelliJ IDEA搭建SpringBoot的小Demo
首先简单介绍下Spring Boot,来自度娘百科:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进 ...
- SQLServer存储过程 实例,很多语法可以以后参考
SQL代码 alter PROCEDURE sp_addnewdtgtype ( ), @dtgdllcontent image, ) ) AS BEGIN ); declare @v_count i ...
- windows 服务器时间同步失败处理方法
服务器的时间同步失败,通过命令行的形式进行处理. 1.编写时间命令行代码 w32tm /config /manualpeerlist:time.windows.com /syncfromflags:M ...
- dedecms 去掉栏目页的预览功能
首先找到include/typeunit.class.admin.php 再找到 ListAllType 方法,该方法的功能是“读出所有分类” 找到并将该方法内的所以以下代码注释或者删除”<a ...
- mif文件C语言生成
1:正弦波 用函数 sin (x * π/180°) /************************************************** 正弦波 mif 生成 ********** ...
- 配置xtrabackup备份mysql数据库
下载地址:https://www.percona.com/downloads/XtraBackup/LATEST/ 为了方便起见本次安装使用yum源安装方式 1 安装yum源:yum insta ...