Preface
 
    The master-slave replication is commonly used in our product evironment.On account of network lag or replicaton mode,slaves probablly be delayed with master.How to solve the consistency of tables between master and slaves?pt-table-checksum is a suitable tool which you can use efficiently.I'm gonna use the tool to do some tests today.
 
Introduce
 
    pt-table-checksum is a memeber of Percona-Toolkit,it's used to check consistency of tables in online replication environment by execute querries on master(put results into a replica called chckesum table).It will indicate whether there're some inconsistent tables bewteen master and slaves by output on screen with parameter "--print".
 
Procedure
 
1.Comman parameter introduce.
 Connection relevent:
--ask-pass -- Ask user to input a password when executing.
-h hostname/ip
-u username
-p password(specify the password in command line)
-P port
-S socket
-D database
-t tables Important parameter:
--create-replicate-table -- Create database and table(checksum table) mentioned in "--replicate".
--no-check-binlog-format -- Don't check binlog format on all server.
--recursion-method -- Specify the prefferd mode to find slaves if you've got multiple slaves.
--replicate -- Specify the table(default is "percona.checksums") into which the results will be write.
--replicate-check-only -- Check consistency on replica without executing checksum queries on master.Furthermore,it only checks riplica for differences found by previous checksuming. Output relevent:
--explain -- Show without really execute checksum querries.
--progress -- Print progress report(default seconds).
--quite -- Print only important informations on screen(will disable "--progress"). Safety relevent:
--no-check-slave-tables -- Only if you're confirmed that all tables on slave is the same with master's.Then you can set it to avoid breaking of replication when executing pt-table-checksum.
--check-replication-filters -- Don't checksum if any replication filters are set on target replica.
--chunk-size-limit -- Limit the chunk size to avoid performance issues.

2.Examples.

 Master:
(root@localhost mysql3306.sock)[zlm]::>show tables;
+----------------+
| Tables_in_zlm |
+----------------+
| test_ddl |
| test_ddl_no_pk |
| test_innodb |
| test_myisam |
+----------------+
rows in set (0.00 sec) Slave:
(root@localhost mysql3306.sock)[zlm]::>show tables;
+----------------+
| Tables_in_zlm |
+----------------+
| t1 |
| t2 |
| t3 |
| test_ddl |
| test_ddl_no_pk |
| test_innodb |
| test_myisam |
+----------------+
rows in set (0.00 sec) ###My pt-table-checksum is installed on master server.Execute the command below on master.### [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums --check-slave-tables -hzlm2 -P3306 -uroot --ask-pass
Enter MySQL password:
-21T10:: DBI connect(';host=zlm2;port=3306;mysql_read_default_group=client','root',...) failed: Access denied for user 'root'@'localhost' (using password: YES) at /usr/bin/pt-table-checksum line . [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums --check-slave-tables -hlocalhost -P3306 -uroot --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
Cannot connect to P=,h=zlm3,p=...,u=root -- It's due to the "root" user cannot login with TCP/IP mode.
Diffs cannot be detected because no slaves were found. Please read the --recursion-method documentation for information.
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
possibly with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-table-checksum line .
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
possibly with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-table-checksum line . # A software update is available:
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
-21T10:: 0.006 mysql.columns_priv
-21T10:: 0.012 mysql.db
-21T10:: 0.010 mysql.engine_cost
-21T10:: 0.008 mysql.event
-21T10:: 0.009 mysql.func
-21T10:: 0.008 mysql.help_category
-21T10:: 0.010 mysql.help_keyword
-21T10:: 0.011 mysql.help_relation
-21T10:: 0.032 mysql.help_topic
-21T10:: 0.008 mysql.ndb_binlog_index
-21T10:: 0.011 mysql.plugin
-21T10:: 0.012 mysql.proc
-21T10:: 0.009 mysql.procs_priv
-21T10:: 0.010 mysql.proxies_priv
-21T10:: 0.009 mysql.server_cost
-21T10:: 0.010 mysql.servers
-21T10:: 0.010 mysql.tables_priv
-21T10:: 0.009 mysql.time_zone
-21T10:: 0.009 mysql.time_zone_leap_second
-21T10:: 0.009 mysql.time_zone_name
-21T10:: 0.009 mysql.time_zone_transition
-21T10:: 0.008 mysql.time_zone_transition_type
-21T10:: 0.007 mysql.user
-21T10:: 0.011 sys.sys_config
-21T10:: 0.008 zlm.test_ddl
-21T10:: 0.008 zlm.test_ddl_no_pk
-21T10:: 0.009 zlm.test_innodb
-21T10:: 0.009 zlm.test_myisam ###See the detail of checksum table.###
(root@localhost mysql3306.sock)[zlm]::>show tables;
+----------------+
| Tables_in_zlm |
+----------------+
| checksums | -- the table checksums was created.
| test_ddl |
| test_ddl_no_pk |
| test_innodb |
| test_myisam |
+----------------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[zlm]::>show create table checksums\G
*************************** . row ***************************
Table: checksums
Create Table: CREATE TABLE `checksums` (
`db` char() NOT NULL,
`tbl` char() NOT NULL,
`chunk` int() NOT NULL,
`chunk_time` float DEFAULT NULL,
`chunk_index` varchar() DEFAULT NULL,
`lower_boundary` text,
`upper_boundary` text,
`this_crc` char() NOT NULL,
`this_cnt` int() NOT NULL,
`master_crc` char() DEFAULT NULL,
`master_cnt` int() DEFAULT NULL,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`db`,`tbl`,`chunk`),
KEY `ts_db_tbl` (`ts`,`db`,`tbl`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
row in set (0.00 sec) ###Check slave hosts information.###
(root@localhost mysql3306.sock)[zlm]::>show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| | | | | 5c77c31b-4add-11e8-81e2-080027de0e0e |
+-----------+------+------+-----------+--------------------------------------+
row in set (0.00 sec) ###Change another user 'repl'@'192.168.1.%' and grant all privileges to it.###
(root@localhost mysql3306.sock)[zlm]::>grant all privileges on *.* to 'repl'@'192.168.1.%';
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[zlm]::>show grants for 'repl'@'192.168.1.%';
+-----------------------------------------------------+
| Grants for repl@192.168..% |
+-----------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'repl'@'192.168.1.%' |
+-----------------------------------------------------+
row in set (0.00 sec) ###Execute pt-table-checksum again.###
[root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums --check-slave-tables -h192.168.1. -P3306 -urepl --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
possibly with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-table-checksum line .
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
possibly with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-table-checksum line . # A software update is available:
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
-21T11:: 0.018 mysql.columns_priv
-21T11:: 0.020 mysql.db
-21T11:: 0.016 mysql.engine_cost
-21T11:: 0.017 mysql.event
-21T11:: 0.014 mysql.func
-21T11:: 0.018 mysql.help_category
-21T11:: 0.016 mysql.help_keyword
-21T11:: 0.015 mysql.help_relation
-21T11:: 0.019 mysql.help_topic
-21T11:: 0.013 mysql.ndb_binlog_index
-21T11:: 0.012 mysql.plugin
-21T11:: 0.015 mysql.proc
-21T11:: 0.012 mysql.procs_priv
-21T11:: 0.016 mysql.proxies_priv
-21T11:: 0.015 mysql.server_cost
-21T11:: 0.015 mysql.servers
-21T11:: 0.014 mysql.tables_priv
-21T11:: 0.013 mysql.time_zone
-21T11:: 0.013 mysql.time_zone_leap_second
-21T11:: 0.015 mysql.time_zone_name
-21T11:: 0.015 mysql.time_zone_transition
-21T11:: 0.012 mysql.time_zone_transition_type
-21T11:: 0.013 mysql.user
-21T11:: 0.015 sys.sys_config
-21T11:: 0.014 zlm.test_ddl
-21T11:: 0.015 zlm.test_ddl_no_pk
-21T11:: 0.021 zlm.test_innodb
-21T11:: 0.016 zlm.test_myisam ###Check whether there're records in "checksums" table or not on slave.###
(root@localhost mysql3306.sock)[zlm]::>select * from checksums where this_cnt<>master_cnt;
+-------+------+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
| db | tbl | chunk | chunk_time | chunk_index | lower_boundary | upper_boundary | this_crc | this_cnt | master_crc | master_cnt | ts |
+-------+------+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
| mysql | proc | | 0.001277 | NULL | NULL | NULL | 9e5a007c | | 4e0f05d9 | | -- :: |
| mysql | user | | 0.000667 | NULL | NULL | NULL | 7de55b47 | | 587dfc7 | | -- :: |
+-------+------+-------+------------+-------------+----------------+----------------+----------+----------+------------+------------+---------------------+
rows in set (0.00 sec)
Supplement
 
1.Drop a table "testl_ddl" on slave when master-slave replication is normally running.
 (root@localhost mysql3306.sock)[zlm]::>show tables;
+----------------+
| Tables_in_zlm |
+----------------+
| checksums |
| t1 |
| t2 |
| t3 |
| test_ddl |
| test_ddl_no_pk |
| test_innodb |
| test_myisam |
+----------------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[zlm]::>drop table test_ddl;
Query OK, rows affected (0.00 sec)

2.Execute pt-table-checksum again.

 [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums --check-slave-tables -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
-22T04:: 0.012 mysql.columns_priv
-22T04:: 0.015 mysql.db
-22T04:: 0.013 mysql.engine_cost
-22T04:: 0.016 mysql.event
-22T04:: 0.014 mysql.func
-22T04:: 0.011 mysql.help_category
-22T04:: 0.015 mysql.help_keyword
-22T04:: 0.017 mysql.help_relation
-22T04:: 0.018 mysql.help_topic
-22T04:: 0.014 mysql.ndb_binlog_index
-22T04:: 0.013 mysql.plugin
-22T04:: 0.013 mysql.proc
-22T04:: 0.013 mysql.procs_priv
-22T04:: 0.014 mysql.proxies_priv
-22T04:: 0.012 mysql.server_cost
-22T04:: 0.012 mysql.servers
-22T04:: 0.014 mysql.tables_priv
-22T04:: 0.014 mysql.time_zone
-22T04:: 0.013 mysql.time_zone_leap_second
-22T04:: 0.012 mysql.time_zone_name
-22T04:: 0.014 mysql.time_zone_transition
-22T04:: 0.014 mysql.time_zone_transition_type
-22T04:: 0.015 mysql.user
-22T04:: 0.012 sys.sys_config
-22T04:: Skipping table zlm.test_ddl because it has problems on these replicas:
Table zlm.test_ddl does not exist on replica zlm3
This can break replication. If you understand the risks, specify --no-check-slave-tables to disable this check.
-22T04:: Error checksumming table zlm.test_ddl: Error getting row count estimate of table zlm.test_ddl on replica zlm3: DBD::mysql::db selectrow_hashref failed: Table 'zlm.test_ddl' doesn't exist [for Statement "EXPLAIN SELECT * FROM `zlm`.`test_ddl` WHERE 1=1"] at /usr/bin/pt-table-checksum line 6823. -22T04:: 0.002 zlm.test_ddl
-22T04:: 0.014 zlm.test_ddl_no_pk
-22T04:: 0.014 zlm.test_innodb
-22T04:: 0.014 zlm.test_myisam ###This will always lead to "ERROR 1146" what is shown below.###
Last_Errno:
Last_Error: Error 'Table 'zlm.test_ddl' doesn't exist' on query. Default database: 'zlm'. Query: 'REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT 'zlm', 'test_ddl', '', NULL, NULL, NULL, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `id`, convert(`name` using utf8mb4), `tel`, CONCAT(ISNULL(`tel`)))) AS UNSIGNED)), , )), ) AS crc FROM `zlm`.`test_ddl` /*checksum table*/'
...
Last_SQL_Errno:
Last_SQL_Error: Error 'Table 'zlm.test_ddl' doesn't exist' on query. Default database: 'zlm'. Query: 'REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT 'zlm', 'test_ddl', '', NULL, NULL, NULL, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `id`, convert(`name` using utf8mb4), `tel`, CONCAT(ISNULL(`tel`)))) AS UNSIGNED)), , )), ) AS crc FROM `zlm`.`test_ddl` /*checksum table*/'

3.Use parameter "--no-check-slave-tables" when execute pt-table-checksum.

 [root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums --no-check-slave-tables -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
-22T04:: 0.017 mysql.columns_priv
-22T04:: 0.015 mysql.db
-22T04:: 0.013 mysql.engine_cost
-22T04:: 0.011 mysql.event
-22T04:: 0.010 mysql.func
-22T04:: 0.011 mysql.help_category
-22T04:: 0.015 mysql.help_keyword
-22T04:: 0.012 mysql.help_relation
-22T04:: 0.015 mysql.help_topic
-22T04:: 0.013 mysql.ndb_binlog_index
-22T04:: 0.012 mysql.plugin
-22T04:: 0.012 mysql.proc
-22T04:: 0.012 mysql.procs_priv
-22T04:: 0.015 mysql.proxies_priv
-22T04:: 0.013 mysql.server_cost
-22T04:: 0.014 mysql.servers
-22T04:: 0.013 mysql.tables_priv
-22T04:: 0.012 mysql.time_zone
-22T04:: 0.013 mysql.time_zone_leap_second
-22T04:: 0.013 mysql.time_zone_name
-22T04:: 0.011 mysql.time_zone_transition
-22T04:: 0.012 mysql.time_zone_transition_type
-22T04:: 0.012 mysql.user
-22T04:: 0.011 sys.sys_config
-22T04:: Error checksumming table zlm.test_ddl: Error getting row count estimate of table zlm.test_ddl on replica zlm3: DBD::mysql::db selectrow_hashref failed: Table 'zlm.test_ddl' doesn't exist [for Statement "EXPLAIN SELECT * FROM `zlm`.`test_ddl` WHERE 1=1"] at /usr/bin/pt-table-checksum line 6823. -22T04:: 0.001 zlm.test_ddl
-22T04:: 0.013 zlm.test_ddl_no_pk
-22T04:: 0.011 zlm.test_innodb
-22T04:: 0.014 zlm.test_myisam ###If slave has already down,then it will wait until you handle the issue and restart slave.###
[root@zlm2 :: ~]
#pt-table-checksum --no-check-binlog-format --replicate=zlm.checksums --no-check-slave-tables -h192.168.1. -P3306 -urepl --ask-pass
Enter MySQL password:
Checking if all tables can be checksummed ...
Starting checksum ...
Replica zlm3 is stopped. Waiting.
Replica zlm3 is stopped. Waiting.
Replica zlm3 is stopped. Waiting.
Summary
  • pt-table-checksum is a light tool with less influence of performance.
  • pt-table-checksum use CRC arlgorism instead of MD5 and SHA1 to reduce consumption of CPU.
  • Parameter "--no-check-binlog-format" is necessary while replications are using "row" binlog format.
  • You can implement pt-table-checksum tool on either master or slave even other third server which is not belongs to replicaitons at all.

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

  1. NXP ARM Vector Table CheckSum

    Signature Creator for NXP Cortex-M Devices Algorithm for creating the checksum The reserved Cortex-M ...

  2. DROP TABLE 恢复【一】

    当DROP TABLE指令敲下的时候,你很爽,你有考虑过后果么?如果该表真的没用,你DROP到无所谓,如果还有用的,这时你肯定吓惨了吧,如果你有备份,那么恭喜你,逃过一劫,如果没有备份呢?这时就该绝望 ...

  3. IAR EWARM Checksum Technical Note

    IELFTOOL Checksum - Basic actions EW targets: ARM, RH850, RX, SH, STM8 EW component: General issues ...

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

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

  5. pt-table-checksum

    pt-table-checksum是percona公司提供的一个用于在线比对主从数据一致性的工具. 实现原理 将一张大表分成多个chunk,每次针对一个chunk进行校验,同时将校验的结果通过REPL ...

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

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

  7. pt-table-checksum解读

    pt-table-checksum是目前可以说是最好的查看主从一致性的工具 先来个使用例子,有助快速上手使用 在主库执行: mysql>GRANT SELECT, PROCESS, SUPER, ...

  8. mysql数据一致性检查及修复

    percona-toolkit-2.2.20-1.noarchmysql 5.6.29-logmaster:192.168.166.129slave:192.168.166.131 一.创建数据库校验 ...

  9. MySQL 错误集-汇总

    Q&A: MySQl报错之@@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ON 导入的时候加入-f参数即可 原因分 ...

随机推荐

  1. PAT 1064 Complete Binary Search Tree

    #include <iostream> #include <cstdio> #include <cstdlib> #include <vector> # ...

  2. css3 转换 过渡 及动画

    转换transform: 通过 CSS3 转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸.您可以使用 2D 或 3D 转换来转换您的元素 2D转换属性: transform 向元素应用 2D 或 ...

  3. Android XMPP 例子(Openfire+asmack+spark) 出现登陆连接错误

    Android XMPP 例子(Openfire+asmack+spark) 运行出来没问题,但是登陆的时候出现如下错误: 出现错误: 09-17 15:24:16.388: E/AndroidRun ...

  4. Linux中怎么从root用户切换到普通用户

    su是在用户间切换,可以是从普通用户切换到root用户, test@ubuntu:~$ su Password:  root@ubuntu:/home/test# 也可以是从root用户切换到普通用户 ...

  5. Mantis查看问题列表的列名修改_"P","#"两列

    在使用mantis的时候,点击菜单上的“查看问题”进去,就会罗列出当前的bug列表,可是列表的标题上存在着“P”和“#”的显示,个人觉得这两列在这里完全没有意义,或者说现有的显示使人觉得疑惑,究竟代表 ...

  6. mybatis中sql语句查询操作

    动态sql where if where可以自动处理第一个and. <!-- 根据id查询用户信息 --> <!-- public User findUserById(int id) ...

  7. jQuery 资料

    jQuery 元素选择器 jQuery 使用 CSS 选择器来选取 HTML 元素. $("p") 选取 <p> 元素. $("p.intro") ...

  8. 通过yum安装最新服务

    给yum添加所安装服务最新rpm源  #这里用mysql为例 # wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm # y ...

  9. leetcode 62、Unique Paths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  10. python接口测试-项目实践(二)获取接口响应,取值(re、json)

    一 分别请求3个接口,获取响应. 第三方接口返回有两种:1 纯字符串  2 带bom头的json字串 import requests api1 = 'url1' response1 = request ...