The MySQL Drop Database is used to drop all the tables and deletes the database itself. First, let us see how to Delete a Database with an example, and here we will use both the command prompt and Workbench.
MySQL Delete Database example
This example shows you how to perform using a command prompt. However, before we delete or drop any of them, Let me show you the list of available MySQL Databases. To get this information, you have to use the SHOW DATABASES command.
The following screenshot will show you the list of available DBS.
The basic syntax to Delete or Drop a Database in MySQL is:
DROP DATABASE Database_Name
For the demonstration of this drop purpose, 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 was executed successfully. And it is saying that 1 row was affected. So, it means there is one table in that database, which is dropped (along with the Database).
Now, let me show you the DBS available. And you can see the first_database is not on the list.
Delete or Drop the Database in MySQL Workbench
To delete a database, let me open the Workbench. From the below screenshot, you can see the list of the available ones under the Schemas pane. Here, there are multiple ways to delete them in a Workbench. Either you can write a drop database statement or use the context menu.
Using Query in Workbench
In this example, we delete second_database using the MySQL Drop Database command.
DROP DATABASE second_database;
Here, the command executes successfully. Now, you can see there is no second_database under schemas
Using Workbench GUI
To delete, Under the SCHEMAS section, Please navigate yourself to the MySQL database you want to drop. Right-click on it will open the context menu. Next, please select Drop Schema…. option from the context menu.
Please select the Drop Now option.
Now you can see that there is no third_database under the schemas.
TIP: Please click on the refresh button beside the Schemas to see updated SCHEMAS.
Best Way to Drop or Delete Database in MySQL
Let us see what will happen if we drop a non-existing using a drop database statement. From the below screenshot, you can observe that it is throwing an error saying: Can’t drop first_database. This is because the DB doesn’t exist.
DROP DATABASE first_database;
The following statement will only execute Drop Database Statement if the first_database is available in the system.
DROP DATABASE IF EXISTS first_database;
Let me try a different name.
DROP DATABASE IF EXISTS fourth_database;