Force drop mysql bypassing foreign key constraint(绕过外键约束强制删除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


基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01