Is there a nice easy way to drop all tables from a MySQL database, ignoring any foreign key constraints that may be in there?
MySQL DROP all tables, ignoring foreign keys
foreign-keysinnodbMySQLsql-drop
Related Topic
- Mysql – concatenate multiple MySQL rows into one field
- Mysql – How to output MySQL query results in CSV format
- Mysql – How to find all tables that have foreign keys that reference particular table.column and have values for those foreign keys
- Mysql – Force drop thesql bypassing foreign key constraint
- Mysql – How to shrink/purge ibdata1 file in MySQL
- MySQL: Grant **all** privileges on database
- MySQL Cannot Add Foreign Key Constraint
Best Answer
I found the generated set of drop statements useful, and recommend these tweaks:
Note 1: This does not execute the DROP statements, it just gives you a list of them. You will need to cut and paste the output into your SQL engine to execute them.
Note 2: If you have VIEWs, you'll have to correct each
DROP TABLE `VIEW_NAME`
statement toDROP VIEW `VIEW_NAME`
manually.Therefore, in order for the drop statements to work if you need:
This will disable referential integrity checks - so when you are done performing the drops you need, you will want to reset key checking with
NB: to use output of SELECT easier, mysql -B option can help.