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 ...
随机推荐
- Mysql5.7的安装配置问题
前些日子安装和配置mysql,遇到一些问题,在这里记录一下. 1.首先,把zip的mysql解压. 2.设置环境变量PATH中添加你的mysql解压目录. 3.在mysql根目录下新建my.ini文件 ...
- 正则表达式把所有Paul替换成Ringo:Paul Puala Pualine paul Paul
代码实现如下: <!DOCTYPE html><html><body> <h2>JavaScript Regular Expressions</h ...
- Csharp:字符串操作
public class StringControl { /// <summary> /// 客户端浏览器 /// http://en.wikipedia.org/wiki/Web_bro ...
- ArcGIS for Server安全与LDAP配置
ArcGIS for Server安全与LDAP配置 1.安全性概述 ArcGIS Server使用基于角色的访问控制来管理对受保护资源的访问.访问GIS资源的权限只能分配给角色.单独的用户只能通过从 ...
- 使用 Python 设置数据的路径
使用 Python 设置数据的路径 编程语言(如 Python)将反斜线 (\) 用作转义字符.例如,\n 表示换行符,\t 表示制表符.指定路径时,可使用正斜线 (/) 代替反斜线.使用两条反斜线( ...
- Format - Numeric
1. 一些常用格式,参考链接:http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx ; Console.WriteLine(v ...
- Android UI 切图命名规范、标注规范及单位描述(转载)
本文转自:https://blog.csdn.net/klxh2009/article/details/74938009 很多UI设计师做APP切图都会有两套,一套是Android的,一套是IOS的. ...
- asyncio标准库4 asyncio performance
性能包括2部分 每秒并发请求数(Number of concurrent requests per second) 每秒请求负载(Request latency in seconds: min/ave ...
- nginx封IP脚本
#!/bin/bash max= confdir=/etc/nginx/conf.d/blockips.conf logdir=/var/log/nginx/access.log echo " ...
- python入门3 python变量,id(),is运算符
python变量无需声明数据类型,可以直接赋值使用. 比如: num=100 #整数 str="字符串" #字符串 turple1 =('mon','tue','wed','thu ...