简体   繁体   English

如何强制截断MySQL中数据库中的所有表(都是innodb)?

[英]How to force truncate all tables(which are all innodb) in a database in MySQL?

I think I get foreign key constraint error when I try to truncate innodb tables. 当我尝试截断innodb表时,我想我得到了外键约束错误。 I was not having problems with this when using MyISAM. 使用MyISAM时,我没有遇到任何问题。

Is there an easy way to force truncate all tables? 是否有一种简单的方法可以强制截断所有表格? Or should I just make a script to drop the database, create new one and then create the tables from scratch? 或者我应该创建一个脚本来删除数据库,创建一个新的,然后从头创建表?

About the FK constraints, you could disable them with next statements - 关于FK约束,您可以使用下一个语句禁用它们 -

SET FOREIGN_KEY_CHECKS = 0;
...DML statements
SET FOREIGN_KEY_CHECKS = 1; -- enable checking

If you have foreign key problems during your operation you can: 如果您在操作过程中遇到外键问题,您可以:

ALTER TABLE tablename DISABLE KEYS

then do your business, and afterwards re-enable keys with: 然后开展业务,然后重新启用密钥:

ALTER TABLE tablename ENABLE KEYS

This techinique is used in MySQL dumps. 此技术用于MySQL转储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM