How to drop all table in MySQL?

Viewed 37317

I don't want to drop database,

because I'm not hosting the website on my own machine,

drop the database will require create it again,and many settings.

Is there a command in MySQL that can be used to delete all tables in a specific database?

EDIT

Everything I can do is within a phpMyAdmin

6 Answers

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]

Here there are more methods to drop all tables without dropping the database.

I'm not aware of anything direct to suit your needs. You might try doing the following:

Run this to show your drop commands:

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | 
grep ^DROP


Nex you can do this to actually execute the drop commands:

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | 
grep ^DROP | 
mysql -u[USERNAME] -p[PASSWORD] [DATABASE]

If your table names have only simple names (no spaces or other special chars) this query could build the whole drop command for you:

select concat('drop table ', group_concat(table_name), ';') from information_schema.tables where table_schema='yourdbname';
Related