MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误
前几天,发现从库挂了,具体报错信息如下:

分析思路
1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect。所以,不太可能出现对于sas_basic的操作能复制到该从库上。
2. 整个架构是1主2从,且都是选择性复制,上面这个从库是直接复制card,upay,deal,monitor,collect这几个数据库的数据,而另外一个从库则是忽略上述库,如下所示:

怀疑是在上述schema下,执行了DROP TABLE IF EXISTS `sas_basic.old_channel_code`操作。
3. 于是根据报错信息查看了主库binlog日志的内容,发现是在sas_basic schema下操作的。
CREATE DATABASE `db1`; USE `db1`; CREATE TABLE `table1` (`ID` bigint(20) primary key) ENGINE=InnoDB; CREATE TABLE `table2` ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `DIVISION_ID` bigint(20) DEFAULT NULL, PRIMARY KEY (`ID`), KEY `FK_TABLE1_DIVISION_1` (`DIVISION_ID`), CONSTRAINT `FK_TABLE1_DIVISION_1` FOREIGN KEY (`DIVISION_ID`) REFERENCES `table1` (`ID`) ON DELETE CASCADE ) ENGINE=InnoDB; DROP TABLE IF EXISTS `table1`;
结果,replicate-ignore-db=test这个从库中复制正常,但replicate-do-db=test这个从库的复制却出现问题。报如下错误:
Last_SQL_Error: Query caused different errors on master and slave. Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code= ; Error on slave: actual message='no error', error code=. Default database: 'db1'. Query: 'DROP TABLE IF EXISTS `table1` /* generated by server */'
Replicate_Ignore_Server_Ids:
完美重现现场。
提交这个Bug的哥们同时也给出了一种替代方案
Suggested fix:
The problem seems to be related to the "USE" above as the following works as expected: CREATE DATABASE `db1`;
CREATE TABLE `db1`.`table1` (`ID` bigint() primary key) ENGINE=InnoDB;
CREATE TABLE `db1`.`table2` ( `ID` bigint() NOT NULL AUTO_INCREMENT, `DIVISION_ID` bigint() DEFAULT NULL, PRIMARY KEY (`ID`), KEY `FK_TABLE1_DIVISION_1` (`DIVISION_ID`), CONSTRAINT `FK_TABLE1_DIVISION_1` FOREIGN KEY (`DIVISION_ID`) REFERENCES `db1`.`table1` (`ID`) ON DELETE CASCADE ) ENGINE=InnoDB;
DROP TABLE IF EXISTS `db1`.`table1`; however if you add an USE `db1` after the CREATE DATABASE statement the replication error will follow.
即在其它schema中删除该表。
但经过测试,无论是在其它schema中执行该操作还是不指定数据库执行该操作,均会使得复制中断。
总结:
1. 该Bug不仅仅在replicate-ignore-db会触发,在replicate-do-db中也会触发。
2. 官方承诺会在5.6.30和5.7.12修复,具体未测。
MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误的更多相关文章
- MySQL:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
MySQL在删除一张表时出现 ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fa ...
- ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails ()
centos7.5 删除表空间文件失败 问题: mysql> alter table country discard tablespace; ERROR 1451 (23000): Cannot ...
- ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
mysql 删除表时提示有外键 mysql> drop tables auth_group;ERROR 1217 (23000): Cannot delete or update a paren ...
- Mysql - 删除表时出现: Cannot delete or update a parent row: a foreign key constraint fails
现象 MySQL在删除一张表时出现 ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint ...
- mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
mysql删除有外链索引数据Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法查询:DELETE ...
- Mysql之1451 - Cannot delete or update a parent row: a foreign key constraint fails...解决办法记录
今天使用delete语句删除一张表中的一条信息时,提示了这么一个错误:1451 - Cannot delete or update a parent row: a foreign key constr ...
- mysql 在删除数据出现Cannot delete or update a parent row: a foreign key constraint fails 这个该如何解决
mysql 在删除数据出现Cannot delete or update a parent row: a foreign key constraint fails 这个该如何解决 可以这样解决: S ...
- MYSQL: Cannot delete or update a parent row: a foreign key constraint fails
这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据.可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况. SET FOREIGN_KEY_CHE ...
- 关于mysql中[Err] 1451 -Cannot delete or update a parent row: a foreign key constraint fails
mysql> SET FOREIGN_KEY_CHECKS = 0; Query OK, 0 rows affected (0.02 sec) mysql> delete from r ...
随机推荐
- 前端面试那些坑之HTML篇
HTML 1.Doctype作用?标准模式与兼容模式各有什么区别? (1).<!DOCTYPE>声明位于位于HTML文档中的第一行,处于<html> 标签之前.告知浏览器的解析 ...
- python lxml install
之前记得安装libxslt和libxml yum install libxml* -yyum install libxslt* -y wget http://lxml.de/files/lxml-3. ...
- Oracle解锁与加锁(HR用户为例)
SQL*Plus: Release 9.2.0.4.0 - Production on Tue Jul 14 18:12:38 2009 Copyright (c) 1982, 2002, Ora ...
- 2015-12-23-( dispaly:table的用法)
dispaly属性的table和table-cell属性值不怎么常用,主要是浏览器的兼容性不好,大多数都是为了兼容IE6.IE7,此属性IE8以上,谷歌,火狐,oprea等浏览器都支持. 此disp ...
- 【转】angular指令入坑
独立作用域和函数参数 通过使用本地作用域属性,你可以传递一个外部的函数参数(如定义在控制器$scope中的函数)到指令.这些使用&就可以完成.下面是一个例子,定义一个叫做add的本地作用域属性 ...
- django 在字符串[str(list)]中精确查找
1.问题描述 1.1表结构 1.2问题 ref_list为id列表的字符串,需要从ref_list中找出包含指定id的数据(eg id=8).如果实用models.objects.filter(ref ...
- Putty部署tomcat
webserver下是tomcatprojects放置项目源代码webapp下放置项目 1. 输入地址栏 登入进去32 192.168.1.32 端口号22 2.进入projects文件夹 cd pr ...
- xxxxxxxx
class IndexHandler(BaseRequestHandler): def get(self, page=1): print('iiiiiiiiiiiiiiiii') current_ti ...
- java读写Properties属性文件公用方法
Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件. 它提供了几个主要的方法: 1. getProperty ( String ...
- [转]ios push
转:http://blog.csdn.net/showhilllee/article/details/8631734 APNS的推送机制 首先我们看一下苹果官方给出的对ios推送机制的解释.如下图 P ...