绕过外键约束强制删除mysql

Force drop mysql bypassing foreign key constraint(绕过外键约束强制删除mysql)

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

问题描述

我正在尝试从数据库中删除除一个之外的所有表,但最终出现以下错误:

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 将我瞄准了一些建议以下方法的网站:

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;

简短的回答是它并没有真正起到作用,因为我最终收到了同样的错误,而我能够删除更多的表.我在 Stack Overflow 上看到了将所有外键链接到某个表的方法,但这太耗时了,除非我全部编写脚本(在没有其他选项的情况下这是可行的)

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)

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

Database is 4.1 so I can't use DROP DATABASE

想法?

推荐答案

由于您对保留任何数据不感兴趣,删除整个数据库并创建一个新的.

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

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

本文标题为:绕过外键约束强制删除mysql

基础教程推荐