开发者

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

开发者 https://www.devze.com 2023-02-22 23:26 出处:网络
I think I get foreign key constraint error when I try to truncate innodb tables. I was not having problems with this when using MyISAM.

I think I get foreign key constraint error when I try to truncate innodb tables. I was not having problems with this when using 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 -

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消