MySQL

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

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

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 🙂

 

Nachiket Panchal

Founder & Administrator of `errorsea` Having interest in Programming & Technology.

Recent Posts

5 Important Things To Know About WordPress Before You Use It

There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…

3 years ago

How to Install MySQL on Your PC in 3 Easy Steps

In this tutorial, I'm going to show you how to install MySQL on your computer.…

4 years ago

Download and Install Turbo C++ for Windows 10 (Full Installation Guide)

Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…

5 years ago

PHP .HTACCESS Redirects

We can redirect any webpage to any other or redirect the whole domain or website…

5 years ago

PHP Redirect Pages

There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…

5 years ago

PHP Include & Required

Include files in PHP are used in appending various global or config files. We can…

5 years ago