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
- Select a MySQL Database on Linux via Command Line
- How to Backup and Restore a MySQL Database
- 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.
- 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.
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.
The following output displays.
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec)
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.
- 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
- Create 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.
Guide on Connecting to Remote Servers Using SSH in Linux, Windows, or macOS SystemsRead Article
New User Tutorial: What is DNS?Read Article