Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I drop all tables in my database?

Tags:

mysql

How can I drop all tables in my database ?

1) In one MYSQL command

2) Without destroying and creating the database ?

Thanks

like image 505
aneuryzm Avatar asked Sep 18 '10 13:09

aneuryzm


People also ask

How do I Drop multiple tables at once?

To drop multiple tables in phpMyAdmin select the page which shows all the tables for a database. Tick the boxes for the tables you want to delete, and select "Drop" from the "With selected:" drop down box. This is shown in the screenshot below where all three tables have been checked: categories, orders and products.

How do I Drop all tables in a schema?

You can select all the available tables from the right sidebar, right click and choose Delete.. , or press Delete key to drop all.


1 Answers

Try something like this:

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

Neat little trick, and it works for me.

Originally suggested here.

like image 61
Michael Gorsuch Avatar answered Oct 23 '22 04:10

Michael Gorsuch