The MySQL Drop Database is useful to drop all the tables and delete 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 Databases. To get this information, you have to use the SHOW DATABASES command.
SHOW DATABASES;
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;
Within the below screenshot, the first statement (SHOW DATABASES) will show you the list of available DBS. Next, the screenshot shows that the DROP DATABASE command to delete DB was executed successfully. And it says that 1 row was affected. So, it means there is one Database with that name, which is dropped (along with the Tables).
Now, let me use the SHOW command to show you the available DBS one more time. 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 Drop Database command.
DROP DATABASE second_database;
Here, the command executes successfully. Now, you can see there is no second_database under schemas
Delete DB 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 the Drop Schema…. option from the context menu. It opens a new pop-up window with Review and Drop Now options. Please choose Drop Now to delete the third one.
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: Error Code: 1008. Can’t drop first_database. This is because the DB doesn’t exist.
DROP DATABASE first_database;
The following statement will only execute the 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;