MySQL Drop Database

In Database Management Systems managing databases involves not only creating and modifying the data but also removing the databases when they are no longer needed and freeing the space occupied by them. MySQL offers a feature called DROP DATABASE, allowing users to delete databases. In this article, We will see How to Drop Databases in MySQL, various methods of dropping databases, and considerations for the process.

MySQL Drop Database

The DROP DATABASE command in MySQL is an important tool used to permanently delete an entire database and it also deletes the data, tables, views, and stored procedures that are associated with the database. The DROP DATABASE command is irreversible and can result in the loss of critical data if not used properly. Due to this, the dropping of the database should be executed with care as it erases all information within the specified database.

Different Ways to Drop the Database

Dropping a database in MySQL can be achieved through several methods. Some most important ones are given below.

  • Dropping Database using MySQL Command Line Client.
  • Dropping Database using MySQL Workbench.

DROP Database using MySQL Command Line Client

Using the MySQL Command Line Interface (CLI), the DROP DATABASE command is executed with the database name specified:

DROP DATABASE database_name;

Explanation: This command permanently erases the specified database, so ensure the correct database name is used to prevent unintended deletions.

Examples of DROP Database

Examples 1

Create the Database using the Command Line Interface, see the below command to Creating Database Library.

Query:

CREATE DATABASE library;

Output:

Create the database

Examples 2

Retrieve the List of Database to Confirm that the Database is Created Successfully.

SHOW DATABASES;

Output:

Examples 3

Drop the Database library using the following Command.

DROP DATABASE library;

Output:

Examples 4

Verifying that the database library is deleted successfully from the list of databases

SHOW DATABASES;

Output:

DROP Database using MySQL Workbench

MySQL Workbench is a visual interface for MySQL, offers an alternative method to dropping the database. Follow the below process step by step to drop the database using MySQL Workbench.

  • Navigate to the SCHEMAS Section in the Sidebar.
  • Right-Click on the target Database and Select Drop Schema.
  • Confirm the Deletion in the Prompt.

Step 1: Navigate to the SCHEMAS Section in the Sidebar.

Step 2: Right Click on the Target Database and Select Drop Schema.

Step 3: Confirm the Deletion in the Prompt.

Conclusion

In this article we learn that the DROP DATABASE command in MySQL provides a method to permanently delete the databases. It removes the database which are no longer needed for data storing purpose. While dropping the database we need to take care while using this command is crucial, as it irreversibly erases all data within the specified database. We cannot perform Rollback operation when DROP DATABASE command is used, so needs to use it carefully.