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 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
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.
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 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 6: Delete Selected Database
We can drop the selected database with the DROP DATABASE command.
DROP DATABASE DATABASE_NAME;
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.
I hope now you know how to delete any database from the command line in MySQL.
Keep Coding 🙂