MySQL Delete Database

The MySQL Drop Database is used to drop all the tables present in the database and also deletes the database itself. Let us see how to Delete Database in MySQL with example. Here, we will use both MySQL command prompt and Workbench for MySQL Delete Database

MySQL Delete Database example

In this example, we will show you how to delete a database in MySQL using a command prompt. Before we start deleting a database, Let me show you the list of available Databases in MySQL Server. To get this information, you have to use the SHOW DATABASES command.

SHOW DATABASES;

The following screenshot will show you the list of available databases.

MySQL Delete Database 1

The basic syntax to Delete a database or Drop MySQL Database is:

DROP DATABASE Database_Name

For the demonstration of drop database purposes, we are going to delete the First_Database. So, Replace the Database_Name with First_Database, as shown below.

DROP DATABASE First_Database;

From the below screenshot, you can see that the command executed successfully. And it is saying that 1 row affected. It means, there is one table in that MySQL database, and that table is dropped (along with the Database).

MySQL Delete Database 2

Now, let me show you the databases available. And you can see the first_database is not on the list.

MySQL Delete Database 3

MySQL Delete Database in Workbench

To delete a database, let me open the Workbench. From the below screenshot, you can see the list of the available database under the Schemas pane. Here, there are multiple ways to delete a database in Workbench. Either you can write MySQL drop database statement or use the context menu.

MySQL Delete Database 4

MySQL Drop Database using Query in Workbench

In this example, we delete second_database database using Drop database command

DROP DATABASE second_database;

Here, the command executed successfully. Now, you can see there is no second_database under schemas

MySQL Delete Database 5

MySQL Drop Database using Workbench GUI

To delete or drop the database in MySQL, Under the SCHEMAS section, Please navigate yourself to the database that you want to drop. Right-click on it will open the context menu. Please select Drop Schema…. option from the context menu.

MySQL Delete Database 6

Please select Drop Now option.

MySQL Delete Database 7

Now you can see, there is no third_database under the schemas.

MySQL Delete Database 8

TIP: Please click on the refresh button beside the Schemas to see updated SCHEMAS.

Best way to Delete Database

Let us see what will happen if we drop a non-existing database using MySQL drop database statement. From the below screenshot, you can observe that it is throwing an error saying: Can’t drop database first_database. The database doesn’t exist.

DROP DATABASE first_database;
MySQL Delete Database 9

The following statement will only execute Drop Database Statement if the first_database in available in the system database

DROP DATABASE IF EXISTS first_database;
MySQL Delete Database 10

Let me try a different database name with MySQL drop database command

DROP DATABASE IF EXISTS fourth_database;
MySQL Delete Database 11