The MySQL Drop Database is used to drop all the tables present in the database, and also deletes the database itself.
In this article we will show you, 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 database in mysql using command prompt. Before we start deleting a database, Let me show you the list of available Databases in MySQL Server. In order to get this information you have to use SHOW DATABASES command
The following screenshot will show you the list of available databases.
The basic syntax to Delete a database or Drop MySQL Database is:
DROP DATABASE Database_Name
For the demonstration of drop database 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 can see that the command is executed successfully. And it is saying that 1 row is effected. It means, there is one table in that database, and that table is dropped (along with database).
Now, let me show you the databases available. And you can see the first_database is not in the list
MySQL Delete Database in Workbench
In order to delete database, let me open the Workbench. From the below screenshot, you can see the list of available database under the Schemas pane.
Here, there are multiple ways to delete database in Workbench. Either, you can write MySQL drop database statement or use context menu.
MySQL Drop Database using Query in Workbench
In this example, we delete second_database database using Drop database command
DROP DATABASE second_database;
Here, command is executed successfully. Now, you can see there is no second_database under schemas
MySQL Drop Database using Workbench GUI
In order to drop 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.
Please select Drop Now option.
Now you can see, 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 Delete MySQL 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 error saying: Can’t drop database first_database. database doesn’t exists.
DROP DATABASE first_database;
The following statement will only execute Drop Database Statement, if the first_database in available in system database
DROP DATABASE IF EXISTS first_database;
Let me try different database name with MySQL drop database command
DROP DATABASE IF EXISTS fourth_database;