Delete a MySQL or MariaDB Database via Command Line

Posted on by Ronald Caldwell
Reading Time: 2 minutes

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.


  • 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.
How to Delete A Database In MySQL/MariaDB

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.


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;
Get 75% off a VPS!

Step 3: View All MySQL Databases

To view a list of databases, issue the following command.


The following output displays.

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

Series Navigation
<< Previous Article
Avatar for Ronald Caldwell

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.

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article