开发环境从库复制出错,错误信息如下:
mysql> show slave status\G;
Last_Errno: 1217
Last_Error: Error 'Cannot delete or update a parent row: a foreign key constraint fails' on query.
# perror 1217
MySQL error code 1217 (ER_ROW_IS_REFERENCED): Cannot delete or update a parent row: a foreign key constraint fails
mysql> show variables like 'foreign_key_checks';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| foreign_key_checks | ON |
+--------------------+-------+
1 row in set (0.00 sec)
解决方法:
1.先停掉slave,禁止外键约束检测,启动slave;
stop slave; set global foreign_key_checks =off;start slave;
2.通过 show slave status\G 观察同步复制正常后,启动外键约束检测,重新启动复制。
set global foreign_key_checks =off;stop slave;start slave;
此操作仅限于开发环境,生产环境慎用。