Delete a MySQL or MariaDB Database via Command Line
- Change a Password for MySQL on Linux via Command Line
- Create a MySQL Database on Linux via Command Line
- MySQL Select Database on Linux Via Command Line
- How to Backup a Database: Complete Guide
- Delete a MySQL or MariaDB Database via Command Line
Knowing how to delete a MySQL or MariaDB database via command line comes in handy. System administrators may need to delete databases when taking care of their tasks. It is a useful skill, and this tutorial shows you how to do it.
Prerequisites
- Server running CentOS or AlmaLinux with MySQL or MariaDB.
- Root access to the server and log in as root.
- Create a database if one does not exist.
Video by Andrew Casares
How to Delete a MySQL or MariaDB Database via Command Line
Step 1: Log into the MySQL Server
The following command allows logging in to the MySQL server from the command line as root. It specifies the root user with the -u flag and uses the -p flag to prompt for a password.
mysql -u root -p
Enter your current password to log in. You can change a password for MySQL via the command line also, if necessary.
Once complete, you reach a MySQL prompt.
mysql>
Step 2: Delete a Database in MySQL or MariaDB
Note: Removing a MySQL or MariaDB database cannot be undone.
The following command deletes your database in MySQL. For this tutorial, the command removes the database named tutorial_database.
DROP DATABASE tutorial_database;
The following error appears only if a database with the name tutorial_database does not exist.
ERROR 1008 (HY000): Can't drop database 'tutorial_database'; database doesn't exist
A way to avoid seeing this error is using the following syntax, which removes the database only if it exists.
DROP DATABASE IF EXISTS tutorial_database;
Step 3: View All MySQL Databases
To view a list of databases, issue the following command.
SHOW DATABASES;
The following output displays.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
Wrapping Up
This tutorial and video covers how to view and delete a MySQL database from the command line in Linux. It is useful for removing databases that are no longer in use.
Liquid Web offers Linux servers via our VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers. Contact our sales team today to set up your server.
Related Articles:
- Using MySQL Command Line to Create a User
- How to Use Disk Quotas in Dedicated Linux Servers With cPanel
- How to Use Disk Quotas in Dedicated Linux Servers with Plesk
- Remove a MySQL User on Linux via Command Line
- Remove Permissions for a MySQL User on Linux via Command Line
- Grant Permissions to a MySQL User on Linux via Command Line

About the Author: Ronald Caldwell
Ron is a Technical Writer at Liquid Web working with the Marketing team. He has 9+ years of experience in Technology. He obtained an Associate of Science in Computer Science from Prairie State College in 2015. He is happily married to his high school sweetheart and lives in Michigan with her and their children.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Install WordPress on Linux (AlmaLinux)
Read ArticleWhat is CentOS? Everything You Need to Know
Read ArticleWhat is CentOS? Everything You Need to Know
Read ArticleRedis as Cache: How It Works and Why You Should Use It
Read ArticleRefer-a-Friend Program for Website Hosting: Get $100 for Each Friend!
Read Article