Is there a nice easy way to drop all tables from a MySQL database, ignoring any foreign key constraints that may be in there?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
Here's a cursor based solution. Kinda lengthy but works as a single SQL batch:
Building on the answer by @Dion Truter and @Wade Williams, the following shell script will drop all tables, after first showing what it is about to run, and giving you a chance to abort using Ctrl-C.
From http://www.devdaily.com/blog/post/mysql/drop-mysql-tables-in-any-order-foreign-keys:
(Note that this answers how to disable foreign key checks in order to be able to drop the tables in arbitrary order. It does not answer how to automatically generate drop-table statements for all existing tables and execute them in a single script. Jean's answer does.)
Just put here some useful comment made by Jonathan Watt to drop all tables
It helps me and I hope it could be useful
I came up with this modification on Dion Truter's answer to make it easier with many tables:
This returns the entire thing in one field, so you can copy once and delete all the tables (use
Copy Field Content (unquoted)
in Workbench). If you have a LOT of tables, you may hit some limits onGROUP_CONCAT()
. If so, increase the max len variable (andmax_allowed_packet
, if necessary).