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 delete or update a parent row: a foreign key constraint fails ()

原因:

在MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。

解决方法:

mysql> SET FOREIGN_KEY_CHECKS = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> alter table country discard tablespace;
Query OK, 0 rows affected (0.01 sec)

mysql> SET FOREIGN_KEY_CHECKS = 1;
Query OK, 0 rows affected (0.00 sec)
posted @ 2019-03-25 15:05  吕涵之  阅读(971)  评论(0编辑  收藏  举报