≡ Menu

How to empty or drop a MySQL database?

The question is – I need to  empty my MySQL database. I want to delete all tables in it and all the data. Is there a MySQL command or another way to achieve this?

There are several ways to do this – one is to use the command line and the other is to use phpMyAdmin.

How to empty/drop a MySQL database using phpMyAdmin?

Using phpMyAdmin, it is very easy to empty a database.

First, login to phpMyAdmin. Then choose the database from the left frame. This will display all tables in that database in the right frame. See the following image:

All MySQL Tables in phpMyAdmin

The above picture shows all tables in my database. Select all tables by clicking on the checkbox on the left of the table name. Then choose drop in the dropdown box as shown in the following picture:

Drop all tables in phpMyAdmin

When you choose drop, it will ask you whether you want to drop all tables. Click on Yes. This will delete all tables in the database!

How to drop and create the database using the command line mysql?

The command line can be used to drop a mysql database and then create it again. This will quickly remove all tables in the database. If the number of tables are not too many, you could individually drop all tables in the database.

Open a SSH shell session. Then type in the following command:

mysql -u ewhathow_user1 -p

This will open a mysql command line session. (Instead of ewhathow_user1, type in your own username).

Then, follow the following steps:

mysql> drop database ewhathow_ewhathow;
Query OK, 0 rows affected (1.47 sec)

mysql> create database ewhathow_ewhathow;
Query OK, 1 row affected (0.00 sec)

The first command will drop the database ewhathow_ewhathow. The second command will create the database again. Note that the user that you use to drop and create the database needs to have drop and create permissions. This can be easily handled using cPanel.

{ 0 comments… add one }

Leave a Comment