MySQL5.6 GTID模式下同步复制报错不能跳过的解决方法

数据库版本:

mysql> select version();

+------------+
| version() |
+------------+
| 5.6.10-log |
+------------+
1 row in set (0.02 sec)

同步复制信息:

mysql> show slave status\G;

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.8.25
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 5036
Relay_Log_File: M2-relay-bin.000008
Relay_Log_Pos: 408
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Could not execute Write_rows event on table test.t; Duplicate entry '12'
for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000007,
end_log_pos 2267
Skip_Counter: 0
Exec_Master_Log_Pos: 2045
Relay_Log_Space: 3810
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1062
Last_SQL_Error: Could not execute Write_rows event on table test.t; Duplicate entry '12'
for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000007,
end_log_pos 2267
Replicate_Ignore_Server_Ids:
Master_Server_Id: 25
Master_UUID: cf716fda-74e2-11e2-b7b7-000c290a6b8f
Master_Info_File: /usr/local/mysql/data2/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 130313 07:24:43
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: cf716fda-74e2-11e2-b7b7-000c290a6b8f:141-151
Executed_Gtid_Set: cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-140
Auto_Position: 1
1 row in set (0.02 sec)

ERROR:
No query specified

提示主键冲突,由于是测试机,于是我直接跳过,

mysql> set global sql_slave_skip_counter=1;

ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with GTID_MODE = ON.
Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction

提示:由于运行在GTID模式,所以不支持sql_slave_skip_counter语法,如果你想跳过,就必须把事务ID设置为空值。
看来只能用这个方法了。

mysql> show global variables like '%GTID%';

+--------------------------+--------------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------------+
| enforce_gtid_consistency | ON |
| gtid_executed | cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-140 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-140 |
+--------------------------+--------------------------------------------+
5 rows in set (0.04 sec)

mysql> set global gtid_executed='';
ERROR 1238 (HY000): Variable 'gtid_executed' is a read only variable
mysql>
mysql> set global gtid_purged='';

ERROR 1840 (HY000): GTID_PURGED can only be set when GTID_EXECUTED is empty.
郁闷,直接设置还不行。

查看了手册,需要执行reset master才可以(注:在从上执行啊,千万别在主上)。

mysql> reset master;
Query OK, 0 rows affected (0.16 sec)

mysql> reset slave;
ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first
mysql> stop slave;
Query OK, 0 rows affected (0.08 sec)

mysql> reset slave;
Query OK, 0 rows affected (0.16 sec)

执行reset slave的目的是清空master.info和relay-log.info,以便后面重新change master to主从复制。
还记得刚才的gtid_purged那个点吗,只需重新设置下一个点即可。

下面是步骤:

mysql> show global variables like '%GTID%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| enforce_gtid_consistency | ON |
| gtid_executed | |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | |
+--------------------------+-------+
5 rows in set (0.06 sec)

mysql> set global gtid_purged='cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-141';
Query OK, 0 rows affected (0.16 sec)

mysql> CHANGE MASTER TO MASTER_HOST='192.168.8.25',MASTER_USER='repl',MASTER_PASSWORD='repl'
,MASTER_AUTO_POSITION = 1;
Query OK, 0 rows affected, 2 warnings (0.32 sec)

mysql> start slave;
Query OK, 0 rows affected (0.13 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.8.25
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 5036
Relay_Log_File: M2-relay-bin.000008
Relay_Log_Pos: 408
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1050
Last_Error: Error 'Table 't0' already exists' on query.
Default database: 'test'. Query: 'create table t0 like t'
Skip_Counter: 0
Exec_Master_Log_Pos: 2298
Relay_Log_Space: 3557
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1050
Last_SQL_Error: Error 'Table 't0' already exists' on query.
Default database: 'test'. Query: 'create table t0 like t'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 25
Master_UUID: cf716fda-74e2-11e2-b7b7-000c290a6b8f
Master_Info_File: /usr/local/mysql/data2/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 130313 07:50:42
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: cf716fda-74e2-11e2-b7b7-000c290a6b8f:142-151
Executed_Gtid_Set: cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-141
Auto_Position: 1
1 row in set (0.02 sec)

ERROR:
No query specified
### 看,这里的报错信息已经不一样了,按照这种方法,重复执行,直到同步复制正常。

mysql> stop slave;
Query OK, 0 rows affected (0.07 sec)

mysql> reset master;
Query OK, 0 rows affected (0.17 sec)

mysql> reset slave;
Query OK, 0 rows affected (0.16 sec)

mysql> set global gtid_purged='cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-151';
Query OK, 0 rows affected (0.13 sec)

mysql> CHANGE MASTER TO MASTER_HOST='192.168.8.25',MASTER_USER='repl',MASTER_PASSWORD='repl'
,MASTER_AUTO_POSITION = 1;
Query OK, 0 rows affected, 2 warnings (0.33 sec)

mysql> start slave;
Query OK, 0 rows affected (0.11 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.8.25
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 5036
Relay_Log_File: M2-relay-bin.000008
Relay_Log_Pos: 408
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 5036
Relay_Log_Space: 819
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 25
Master_UUID: cf716fda-74e2-11e2-b7b7-000c290a6b8f
Master_Info_File: /usr/local/mysql/data2/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: cf716fda-74e2-11e2-b7b7-000c290a6b8f:1-151
Auto_Position: 1
1 row in set (0.01 sec)

ERROR:
No query specified

呵呵,总算是解决好了,真麻烦啊。如果大家有更好、更方便的解决方法,也给我回帖哦,谢谢。

(0)

相关推荐

  • MySQL5.6 GTID模式下同步复制报错不能跳过的解决方法

    数据库版本: mysql> select version(); +------------+ | version() | +------------+ | 5.6.10-log | +------------+ 1 row in set (0.02 sec) 同步复制信息: mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Wait

  • Linux下安装软件包报依赖等相关问题的解决方法

    目录 背景 1)开启 yum 的 keepchche 功能:方法1 2) yum-utils 软件:方法2 3) lrzsz 下载上传 背景 在内网服务器下无法利用yum进行安装,需要自行安装可能会出现相关依赖报错(依赖软件包版本不兼容)的情况出现,解决思路:可以找一台相同操作系统版本且支持yum下,通过已安装的软件包拷贝到另一台机器上进行安装. 1)开启 yum 的 keepchche 功能:方法1 vi /etc/yum.conf keepcache =1 # 修改为1 例:安装 iptab

  • 微信二次分享报错invalid signature问题及解决方法

    基于微信公众号开发的h5页面(使用jssdk接口),由用户A分享给用户B,用户B再次分享这个页面时,不能成功分享.问题出在用户B收到的分享链接与用户A打开的链接不同 A用户的链接为 http://test.com/test.html B用户收到的连接 http://test.com/test.html&from=singlemessage from=singlemessage是微信客户端为了区分分享来源再链接后自动添加的标记,再次分享时,需要在js代码中对自动获取的连接进行encodeURICo

  • 安装python时MySQLdb报错的问题描述及解决方法

    问题描述: windows安装python mysqldb时报错python version 2.7 required,which was not found in the registry 网上很多方案,比如方案一: Python3.x时, from _winreg import *  改为 from winreg import * 去掉下划线 import sys from _winreg import * # tweak as necessary version = sys.version

  • Windows安装Node.js报错:2503、2502的解决方法

    前言 Windows真的是太恶心了!!!不仅会出现大量的垃圾文件,而且有时莫名的安装不上一些软件(正常软件).前久因为想学学Koa2,打算升级下nodejs的版本以体验下ES6.ES7的aync,await等新特性,却死活安装不上nodejs同时也卸载不了老版的nodejs,不知所措,放了一段时间,今晚想看看D3准备学学,并借助Koa做个展示性的学习练手项目,决心查查资料解决下nodejs安装报错问题. 功夫不负有心人,终于得以解决,故以此文记录下. 目录权限问题? 首先我想是不是权限问题,于是

  • IIS FTP部分文件上传报错451的原因及解决方法

    最近部署一个基于IIS7的ftp服务器,添加一个组的用户具有上传及读取权限,使用Flashfxp软件测试了不同文件的上传下载,均可以正常使用.由于之前建FTP出现过使用浏览器访问不能验证用户的问题,于是也用浏览器进行测试,访问正常.正高兴呢.结果测试传几个文件遇到问题了.部分文件可以正常上传,但部分报错,具体错误提示如下: 找了下资料,发现原来是万国码问题,具体解决方法如下: 在FTP管理器的右边点击"高级设置"--将"允许UTF8"改为[False],如下图:

  • 微信小程序导入Vant报错VM292:1 thirdScriptError的解决方法

    导入执行后 VM292:1 thirdScriptError  sdk uncaught third Error  module "miniprogram_npm/vant-weapp/mixins/transition" is not defined  Error: module "miniprogram_npm/vant-weapp/mixins/transition" is not defined     at require (http://127.0.0.

  • Linux中Oracle启动侦听报错TNS:permission denied的解决方法

    前言 最近在开发环境 oracle 启动侦听的时候,出现了 TNS:permission denied 的问题,通过网上和咨询朋友,最终找到了解决方案,现在共享出来给有需要的朋友. 错误描述 [oracle@oracle ~]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 27-MAR-2015 15:37:59 Copyright (c) 1991, 2009, Oracle. All rights r

  • Django 解决阿里云部署同步数据库报错的问题

    写在最前面: 在阿里云租了一台服务器,搭建了一个博客,采用的是Ubuntu+Django+uwsgi+nginx+mysql的结构. 运行了一段时间后,我发现我忘记了django自带后台的密码! 然后很常规的修改密码的操作,就是无法登陆! 然后想再创建一个超级用户,登上去看看什么情况,结果创建超级用户又报错? 可是本地环境是ok的,然后同步数据库出错...反正没有对的. 然后同步数据库报错如下: 手机端截的图,查了一下报错,应该是setting.py的配置问题,然后我把生产上的代码拿下来看了下.

  • 解决Window10系统下Node安装报错的问题分析

    前言 今天电脑重装了win10系统,在安装Node的过程中出现了下面的问题,下面就和大家分享下用来解决这种问题的小方法. 报错原因 随便问下度娘我们就可以知道,导致报错的原因是由于权限的关系,因此我们只需要使用管理员权限来运行当前Node安装包就可以解决报错问题了. 具体方法 使用管理员权限打开命令行工具并且cd到node安装包的项目文件夹下执行下面代码: msiexec /i package node-v6.9.1-x64.msi 运行指令之后接下来就会自动弹出安装界面,然后我们只需要按照提示

随机推荐