Check-out our new look and give us some feedback!

How to Delete A Database In MySQL/MariaDB

Posted on by J. Mays | Updated:
Reading Time: 2 minutes

Pre-Flight Check

  • These instructions are intended for deleting a MySQL database on Linux via the command line.
  • I’ll be working from a Liquid Web Core Managed CentOS 7 server, and I'll be logged in as root.
How to Delete A Database In MySQL/MariaDB

First, we'll log in to the MySQL server from the command line with the following command:

mysql -u root -p

In this case, I've specified the user root with the -u flag and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login. If you need to change your root (or any other) password in the database, then follow this tutorial on changing a password for MySQL via the command line.

You should now be at a MySQL prompt that looks very similar to this:

mysql>

Follow this tutorial if you have not yet created a database, or you want a list of databases.

Delete a Database in MySQL

It only takes one simple command to delete a database in MySQL, but BEWARE; dropping a database can not be undone! The command is as follows:

DROP DATABASE tutorial_database;

If a database with the name tutorial_database does not exist, then you'll receive this error:

ERROR 1008 (HY000): Can't drop database 'tutorial_database'; database doesn't exist

To avoid seeing this error use the following command instead:

DROP DATABASE IF EXISTS tutorial_database;

The above command will only drop the database tutorial_database if a database of that name exists.

Get 75% off a VPS!

View All MySQL Databases

To view a list of databases simply issue the following command:

SHOW DATABASES;

Your result should be similar to this:

mysql> SHOW DATABASES;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | mysql              |
 | test               |
 +--------------------+
 4 rows in set (0.00 sec)

Video by Andrew Casares

Conclusion

In this tutorial, we covered how to view and delete a MySQL database from the command line in Linux. We also included a handy video which presents a visual representation of how to accomplish this task.

Have further questions on this topic?

Contact us today at 1.800.580.4985 to speak to a knowledgeable systems administrator or Linux admin who can get you the info you need!

Too busy to talk? Click HERE to open a quick chat with us to find out more.

Would you like more info in the form of an email, so you can review the information at your leisure? Email us today to get advice on how this works.

We look forward to hearing from you!

Series Navigation
<< Previous ArticleNext Article >>

About the Author: J. Mays

Latest Articles

How to Edit Your DNS Hosts File

Read Article

How to Edit Your DNS Hosts File

Read Article

Microsoft Exchange Server Security Update

Read Article

How to Monitor Your Server in WHM

Read Article

How to Monitor Your Server in WHM

Read Article