How to Delete Database in MySQL

MySQL is a database server to manage relational databases. There are some methods to delete a database from the MySQL server.

Here we are going to learn to delete a database via MySQL command line. You can use Microsoft cmd, Linux terminal or MAC terminal which one you are using.

In this tutorial, we are going to use Microsoft cmd to delete the database from the MySQL server.

Delete MySQL Database From Command Line

Step 1: Open the Command Line or Terminal on Your Operating System.

We are using here windows command prompt. You can find command prompt at start menu, just search for cmd and it will come up the first.

step 1 open microsoft command line cmd

Step 2: Log In to MySQL Command Line

We have to login to MySQL server via login command in order to access MySQL services on the command line. Write below command and press Enter.

mysql -u root -p

step 2 write mysql command to connect server

Note: If you are having an error like ‘mysql is not recognized as an internal or external command, operable program or batch file.’, this error may appear if you have not set MySQL path as the global environment. In command-line please go to MySQL root directory and change directory to the bin directory and enter the above code there.

Step 3: Enter the MySQL User Password

Please enter your MySQL user password to make a connection and access MySQL services.

step 3 enter password for mysql user

Now we are successfully logged in to MySQL command line.

Step 4: View the List of Databases

Enter ‘SHOW DATABASES‘ command in the command line to display the list of databases.


step 4 show list of mysql databases

Step 5: Select the Database To Delete

We can see the list of all databases and select which one we need to delete. Here we are going to delete test_database to demonstrate.

step 5 select database from list to delete

Step 6: Delete Selected Database

We can drop the selected database with the DROP DATABASE command.


step 6 drop selected database

Note: If you are using Macintosh you need to be case sensitive for the database name.

Step 7: Review Databases for Confirmation

Now the test_database should no longer be available. Check databases list via show databases command again to be sure.

step 7 review databases list to confirm deletion

Read Also: How to Sort Array in PHP [Explained With Examples]

I hope now you know how to delete any database from the command line in MySQL.

Keep Coding 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *