If you are a database or Linux system administrator, then you may often need to delete unwanted databases from your system. There are several ways to delete a MySQL database in Linux. You can either use the MySQL command-line or phpMyAdmin to delete a MySQL database. You must have a MySQL user account with delete privileges to delete a MySQL database from your system.
In this tutorial, we will show you how to delete (or drop) a MySQL or MariaDB database in Linux.
- A server running Linux on the Atlantic.Net Cloud Platform
- A root password configured on your server
Create Atlantic.Net Cloud Server
First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.
Delete MySQL Database with mysqladmin
mysqladmin is a MySQL built-in command-line utility that allows you to create and delete MySQL databases, check MySQL processes, and set a MySQL root password via a command-line interface.
First, use the following command to list all available databases in your system:
mysqlshow -u root -p
You will get a list of all databases in the following output:
+--------------------+ | Databases | +--------------------+ | drupaldb | | information_schema | | magentodb | | mysql | | performance_schema | | sys | | wpdb | +--------------------+
Now, pick the drupaldb database from the above list and delete it by running the following command:
mysqladmin -u root -p drop drupaldb
You should see the following output:
Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'drupaldb' database [y/N] y Database "drupaldb" dropped
How to Install and Use MySQL Workbench on Ubuntu 18.04
Delete MySQL Database within MySQL Console
MySQL databases can also be deleted after logging into the MySQL shell. To do so, log into the MySQL console with the root user using the following command:
mysql -u root -p
Once you are logged in, you should see the following output:
Next, list all available databases with the following command:
mysql> show databases;
You should see all databases in the following output:
+--------------------+ | Database | +--------------------+ | drupaldb | | information_schema | | magentodb | | mysql | | performance_schema | | sys | | wpdb | +--------------------+
Next, delete the MySQL database named magentodb from the above list with the following command:
mysql> drop database magentodb;
Next, exit from the MySQL console with the following command:
You can also delete the MySQL database named wpdb without logging into the MySQL console as shown below:
mysql -u root -p -e "drop database wpdb";
Delete MySQL Database with PhpMyAdmin
Before starting, make sure phpMyAdmin is installed on your server.
Next, open your web browser and access the PhpMyAdmin web UI using the URL http://your-server-ip/phpmyadmin. You should see the following page:
Provide your MySQL root username and password and click on the Go button. You will be redirected to the PhpMyAdmin dashboard on the following page:
Now, click on Databases. You should see all the databases on the following page:
Now, select the database you want to delete and click on the Drop button to delete the selected database.
In the above post, we explained how to delete a MySQL database via command-line and PhpMyAdmin. Try it on a dedicated server from Atlantic.Net!