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.

SHOW 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.

DROP DATABASE DATABASE_NAME;

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

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 *