If you want to drop all tables from a MySQL database without deleting and recreating the database again, maybe because you don't have proper permissions to create databases or for other reasons, you can use this one liner command to list and then drop all of the tables of your database.

For this example, which you'll need to run at the command line, we'll assume the following information and credentials:


mysql username: username

mysql password: password

name of mysql database: mydatabase

 

Ok, so here's the simple command you can use to drop all tables of your database:

mysqldump -uusername -ppassword --add-drop-table --no-data mydatabase| grep ^DROP | mysql -uusername -ppasswordmydatabase

 

That's all you'll need to do, and once you've run that command, you can check your database and see that all of your tables have been removed. As mentioned before, the benefit of dropping tables this way is that you will not need to recreate the entire database.

Share

Comments (0)

No comments found!

Write new comment