mysql 跳过checksum_MySQL-Utilities:mysqldbcompare及跳过复制错误
mysqldbcompare也是MySQL-Utilities工具集的一个脚本。mysqldbcompare从两个数据库比较对象和数据的不同。数据库中的对象包括:表、视图、触发器、存储过程、函数和事件。每一个对象类型计数可以使用-vv选项显示。通过一系列步骤检查进行测试,默认情况下,一旦测试失败就终止检测。可以指定--run-all-tests选项来进行所有的测试。
环境:CentOS6.5源码安装多个MySQL实例及复制搭建,之前做复制时Master实例的test库中的数据表没有复制到Slave实例
#使用Master中的test.test1的建表语句创建Slave中的test.test1,修改列c的说明,并插入数据usetest;create tabletest1
(idint not null primary key,
avarchar(10) not null,
bvarchar(10),
cvarchar(10) comment 'cc',
dint)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test1';insert into test1 values(1,'a','b','c',1);
View Code
此时两表的定义和数据是不一致的。
比较检测的步骤
1、数据库定义的检查 检查对比的数据库是否存在
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test1
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
ERROR: The database test1 does not exist.
View Code
2、检测数据库的对象 检查两者数据库中的对象是否丢失。可以使用--skip-object-compare选项跳过这步。
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
ERROR: The list of objects differs among database test and test.
View Code
3、比较对象的定义 对对象的定义(CREATE语句)进行比较和显示不同。可以使用--skip-diff选项跳过这步。
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test --skip-object-compare
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# TABLE test1 FAIL ERROR: Theobject definitions do not match.
View Code
4、检测表的行数 检查表是否有相同的行数,但这并不确保表的数据是一致性的。可以使用--skip-row-count选项跳过这步。
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test --skip-object-compare --skip-diff# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# TABLE test1 SKIP FAIL ERROR: Row counts are not the same among `test`.`test1` and `test`.`test1`.
View Code
5、检测表数据的一致性 检查行数同时检查数据是否一致,两表需要有主键或唯一索引。可以使用--skip-checksum-table选项跳过表校验,使用--skip-data-check选项跳过数据检查。
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test --skip-object-compare --skip-diff --skip-row-count
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# TABLE test1 SKIP SKIP-#-Compare table checksum FAIL
#-Find row differences FAIL
#
# Transformationfor --changes-for=server2:
#
DELETE FROM `test`.`test1` WHERE `id` = '1';
#
# Transformationfor reverse changes (--changes-for=server1):
#
# INSERT INTO `test`.`test1` (`id`, `a`, `b`, `c`, `d`) VALUES('1', 'a', 'b', 'c', '1');
#
# Database consistency check failed.
#
# ...done#使用--skip-checksum-table选项跳过表校验
[root@VMUest~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test --skip-object-compare --skip-diff --skip-row-count --skip-checksum-table
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# TABLE test1 SKIP SKIP-#-Compare table checksum SKIP
#-Find row differences FAIL
#
# Transformationfor --changes-for=server2:
#
DELETE FROM `test`.`test1` WHERE `id` = '1';
#
# Transformationfor reverse changes (--changes-for=server1):
#
# INSERT INTO `test`.`test1` (`id`, `a`, `b`, `c`, `d`) VALUES('1', 'a', 'b', 'c', '1');
#
# Database consistency check failed.
#
# ...done#使用--skip-data-check选项跳过数据检查
[root@VMUest~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test --skip-object-compare --skip-diff --skip-row-count --skip-checksum-table --skip-data-check
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# TABLE test1 SKIP SKIP SKIP
# Databases are consistent given skip options specified.
#
# ...done
View Code
指定--run-all-tests选项来进行所有的检测
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql test:test --run-all-tests
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases test on server1 and test on server2
#
# WARNING: Objectsin server1.test but not inserver2.test:
# TABLE: test2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# TABLE test1 FAIL FAIL-#-Compare table checksum FAIL
#-Find row differences FAIL
#
# Transformationfor --changes-for=server2:
#
ALTER TABLE `test`.`test1`
CHANGE COLUMN c c varchar(10) NULL COMMENT 'c';
#
# Transformationfor reverse changes (--changes-for=server1):
#
# ALTER TABLE `test`.`test1`
# CHANGE COLUMN c c varchar(10) NULL COMMENT 'cc';
#
# Row counts are not the same among `test`.`test1` and `test`.`test1`.
#
# Transformationfor --changes-for=server2:
#
DELETE FROM `test`.`test1` WHERE `id` = '1';
#
# Transformationfor reverse changes (--changes-for=server1):
#
# INSERT INTO `test`.`test1` (`id`, `a`, `b`, `c`, `d`) VALUES('1', 'a', 'b', 'c', '1');
#
# Database consistency check failed.
#
# ...done
View Code
检测做复制的sakila库
[root@VMUest ~]# mysqldbcompare --server1=mydba:mysql5635@192.168.85.129:3306 --server2=mydba:mysql5635@192.168.85.129:3307 --changes-for=server2 --show-reverse --difftype=sql sakila:sakila
# WARNING: Using a password on the command line interface can be insecure.
# server1 on192.168.85.129: ... connected.
# server2 on192.168.85.129: ... connected.
# Checking databases sakila on server1 and sakila on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
#-------------------------------------------------------------------------# FUNCTION get_customer_balance pass- -# FUNCTION inventory_held_by_customer pass- -# FUNCTION inventory_in_stock pass- -# PROCEDURE film_in_stock pass- -# PROCEDURE film_not_in_stock pass- -# PROCEDURE rewards_report pass- -# TABLE actor pass pass-#-Compare table checksum pass
# TABLE address pass pass-#-Compare table checksum pass
# TABLE category pass pass-#-Compare table checksum pass
# TABLE city pass pass-#-Compare table checksum pass
# TABLE country pass pass-#-Compare table checksum pass
# TABLE customer pass pass-#-Compare table checksum pass
# TABLE film pass pass-#-Compare table checksum pass
# TABLE film_actor pass pass-#-Compare table checksum pass
# TABLE film_category pass pass-#-Compare table checksum pass
# TABLE film_text pass pass-#-Compare table checksum pass
# TABLE inventory pass pass-#-Compare table checksum pass
# TABLE language pass pass-#-Compare table checksum pass
# TABLE payment pass pass-#-Compare table checksum pass
# TABLE rental pass pass-#-Compare table checksum pass
# TABLE staff pass pass-#-Compare table checksum pass
# TABLE store pass pass-#-Compare table checksum pass
# TRIGGER customer_create_date pass- -# TRIGGER del_film pass- -# TRIGGER ins_film pass- -# TRIGGER payment_date pass- -# TRIGGER rental_date pass- -# TRIGGER upd_film pass- -# VIEW actor_info pass- -# VIEW customer_list pass- -# VIEW film_list pass- -# VIEW nicer_but_slower_film_list pass- -# VIEW sales_by_film_category pass- -# VIEW sales_by_store pass- -# VIEW staff_list pass- -# Databases are consistent.
#
# ...done
View Code
感觉mysqldbcompare的--run-all-tests选项包括了mysqldiff。mysqldiff如果指定数据库对(db1:db2),将对比数据库下的对象(不会检查对象的定义);如果指定具体对象(db1.obj1:db2.obj2),将对比其定义。
跳过复制错误
在前面对比数据的第5步做Find row differences操作时,会将下面语句写到二进制日志(实际是对比的双方都会有这样的操作,可开启log_bin查看)
现在已经知道主从的test库不一致,下面测试如何跳过复制错误。在主库删除表test2
mysql> drop tabletest2;
Query OK,0rows affected
mysql> SHOW BINLOG EVENTS in 'mysql-bin.000002' from 16061;+------------------+-------+------------+-----------+-------------+----------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+-------+------------+-----------+-------------+----------------------------------------------------------+
| mysql-bin.000002 | 16061 | Query | 6 | 16179 | use `test`; DROP TABLE `test2` /*generated by server*/ |
+------------------+-------+------------+-----------+-------------+----------------------------------------------------------+
1 row in set
View Code
在从库查看复制状态
mysql>show slave status\G*************************** 1. row ***************************Slave_IO_State: Waitingfor master tosend event
Master_Host:127.0.0.1Master_User: repl
Master_Port:3306Connect_Retry:60Master_Log_File: mysql-bin.000002Read_Master_Log_Pos:16179Relay_Log_File: mysql-relay-bin.000005Relay_Log_Pos:16224Relay_Master_Log_File: mysql-bin.000002Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:1051Last_Error: Error'Unknown table'test.test2'' on query. Default database: 'test'. Query: 'DROP TABLE `test2` /* generated by server */'Skip_Counter:0Exec_Master_Log_Pos:16061Relay_Log_Space:16678Until_Condition: None
Until_Log_File:
Until_Log_Pos:0Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:NULLMaster_SSL_Verify_Server_Cert: No
Last_IO_Errno:0Last_IO_Error:
Last_SQL_Errno:1051Last_SQL_Error: Error'Unknown table'test.test2'' on query. Default database: 'test'. Query: 'DROP TABLE `test2` /* generated by server */'Replicate_Ignore_Server_Ids:
Master_Server_Id:6Master_UUID: 02a05b2c-0557-11e7-bb02-000c29493a20
Master_Info_File:/usr/local/mysql3307/log/master.info
SQL_Delay:0SQL_Remaining_Delay:NULLSlave_SQL_Running_State:
Master_Retry_Count:86400Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:170315 14:21:55Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:0
1 row in set (0.00 sec)
View Code
报错Unknown table,使用下面语句跳过一个事务
mysql>stop slave;
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
mysql> start slave;
View Code
重新查看复制状态
mysql>show slave status\G*************************** 1. row ***************************Slave_IO_State: Waitingfor master tosend event
Master_Host:127.0.0.1Master_User: repl
Master_Port:3306Connect_Retry:60Master_Log_File: mysql-bin.000002Read_Master_Log_Pos:16179Relay_Log_File: mysql-relay-bin.000006Relay_Log_Pos:283Relay_Master_Log_File: mysql-bin.000002Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:0Last_Error:
Skip_Counter:0Exec_Master_Log_Pos:16179Relay_Log_Space:16678Until_Condition: None
Until_Log_File:
Until_Log_Pos:0Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:0Last_IO_Error:
Last_SQL_Errno:0Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:6Master_UUID: 02a05b2c-0557-11e7-bb02-000c29493a20
Master_Info_File:/usr/local/mysql3307/log/master.info
SQL_Delay:0SQL_Remaining_Delay:NULLSlave_SQL_Running_State: Slave hasread all relay log; waiting for the slave I/O thread to updateit
Master_Retry_Count:86400Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:0
1 row in set (0.00 sec)
View Code
对于这种需求明确的通过跳过出错事务就能将主从保持一致。
mysql 跳过checksum_MySQL-Utilities:mysqldbcompare及跳过复制错误相关推荐
- MySQL数据库数据对比工具——Mysqldbcompare
MySQL Utilities介绍 MySQL Utilities 提供一组命令行工具用于维护和管理 MySQL 服务器,包括: 管理工具 (克隆.复制.比较.差异.导出.导入) 复制工具 (安装.配 ...
- 跳过复制错误——slave_skip_errors、slave_exec_mode
这一篇写写复制错误处理相关的另两个参数slave_skip_errors.slave_exec_mode,基本环境参考<复制错误处理--sql_slave_skip_counter> 一. ...
- 青蛙跳台阶c语言递归函数,青蛙跳台阶问题的四种解法
http://raychase.iteye.com/blog/1337359 题目:一只青蛙一次可以跳1级台阶,也可以跳2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 这道题还被ITEye放在了博 ...
- 【鸿蒙 HarmonyOS】界面跳转 ( AbilitySlice 之间的界面跳转 | AbilitySlice 之间的值传递 )
文章目录 一.AbilitySlice 之间的界面跳转 二.完整代码示例 三.运行结果 参考文档 : Page Ability 基本概念 Page Ability 声明周期 AbilitySlice ...
- 今天突然想到一个问题:地球在转动吗,由东西向西跳与由西向东跳哪个更远...
今天突然想到一个问题:地球在转动吗,由东西向西跳与由西向东跳哪个更远 最后想明白了,一般的解释就说惯性,但这个解释太不负责了,其实这类人都不懂. 网上摘的一段说法: 因为人跳起后有惯性,所以还保留与地 ...
- vscode 快速调到定义处_vim技巧:在程序代码中快速跳转,在文件内跳转到变量定义处...
本篇文章介绍 vim 的一些使用技巧: 在程序代码中快速跳转 在文件内跳转到变量定义处 在程序代码中快速跳转 在 vim 中查看代码文件时,可以使用下面命令在程序代码中快速跳转,提高效率. % 跳转到 ...
- js layui跳转页面_【WEB前端开辟】layui的iframe跳转链接与页面按钮跳转相干引见...
一.导航跳转iframe页面题目: 引荐:layui教程 关于layui的iframe嵌套页面的导航跳转页面题目,如下图所示能够看到结果: 在模板页的导航代码: 一切商品 商品列表 商品属性 商品分类 ...
- vue 跳转页面带对象_vue跳转页面的几种方法(推荐)
vue跳转不同页面的多种方法 1:router-link跳转 点击跳转2 点击跳转1 点击跳转3 2:this.$router.push() 点击跳转4 export default{ name:'t ...
- nginx实现网站url带参跳转 POST请求GET请求跳转
应工作需求,访问一个网站时直接跳转到另一个url 目标URL http://123.com.cn/123/123.action?id=3 但是跳转的目标url是带参数的,用传统的方法会在最后加上 '/ ...
最新文章
- linux引导程序切换
- 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)
- 2021巨量引擎汽车直播行业研究报告
- 计算机专业的口号运动会四字,计算机系运动会口号
- eja智能压力变送器工作原理_电量变送器是什么?电量变送器工作原理解析
- 一文快速了解 Java 9 - 16 新特性,网友:卷不动了?
- PTA甲级15进制转换
- appium 学习教程
- MFC中添加工具条(TOOLBAR)
- 《爱的五种能力》读书笔记22.02
- 2020风中劲草pdf电子版完整版 下载
- pthon爬虫笔记--名著小说网
- 漫步者蓝牙自动断开_比苹果AirPods体验更好的蓝牙耳机,漫步者lollipods体验小感...
- C++ 关键字 typeid, typename
- Pointproofs 学习笔记3——代码解析
- html5用一张图片铺满屏幕,html5绘图铺满整个屏幕
- mysql-基础-视图,存储过程,触发器
- 阿里云入门教程搭建云数据库SQL Server
- 微信小程序手机号输入3和7位空格,删除时删除空格
- 三相永磁同步电机(PMSM) SVPWM矢量控制 MATLA 仿真算法