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. 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.
精彩评论