强制删除mysql绕过外键约束 [英] Force drop mysql bypassing foreign key constraint

查看:1105
本文介绍了强制删除mysql绕过外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从数据库中删除除了一个以外的所有表,并且最终出现以下错误:

lockquote

无法删除或者更新一个父行:一个外键约束失败

当然,我可以反复试验看看这些关键约束是什么删除所有的表,但我想知道是否有一个快速的方式强制删除所有表(因为我将能够重新插入那些我不想删除)。

Google在一些网站上向我推荐了以下方法:

  mysql> SET foreign_key_checks = 0; 
mysql>删除表...
mysql> SET foreign_key_checks = 1;简单的答案是它没有真正的伎俩,因为我最终收到同样的错误,而我能够删除更多的表格。我已经看到堆栈溢出的方式来获取所有的外键链接到某个表,但是这太耗费时间,除非我编写脚本(这是可行的,在没有其他选择的情况下)

数据库是4.1,所以我不能使用 DROP DATABASE



因为你不想保留任何数据,所以 解决方案

refman / 5.0 / en / drop-database.htmlrel =nofollow noreferrer>删除整个数据库并创建一个新的。


I'm trying to delete all tables from a database except one, and I end up having the following error:

Cannot delete or update a parent row: a foreign key constraint fails

Of course I could trial and error to see what those key constraints are and eventually delete all tables but I'd like to know if there is a fast way to force drop all tables (as I'll be able to re-insert those I don't want deleted).

Google aimed me at some site that suggested the following method:

mysql> SET foreign_key_checks = 0;
mysql> drop table ...
mysql> SET foreign_key_checks = 1;

Short answer is it didn't really do the trick since I ended up receiving the same error while I was able to delete some more tables. I've seen on Stack Overflow ways to get all foreign keys linked to a certain table but that's way too time consuming unless I script it all (which is doable in the case there is no other option)

Database is 4.1 so I can't use DROP DATABASE

Ideas?

解决方案

Since you are not interested in keeping any data, drop the entire database and create a new one.

这篇关于强制删除mysql绕过外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆