How To Delete MySQL Databases & Users From Your MySQL Server
In a previous article, we created a Remote MySQL Database Server on one of our NVMe VPS Servers, then we installed a copy of WordPress on a different server. We created a database and user and connected them together. Now we are going to look at how we manage that user. Specifically, we want to learn how to delete the MySQL databases and the user.
This guide will also work on MariaDB servers as MariaDB is basically a copy of MySQL. Login to your MySQL/MariaDB database server as the root user to proceed. Next, issue the below command to log in to MySQL. You will need to Reset The MySQL Root Password if you have forgotten it or you don’t know it.
mysql -u root -p mysql
List MySQL Users
Your console will now display mysql>. We can see a list of MySQL users on this server by issuing the following command;
SELECT User,Host FROM mysql.user;
So, here we can see the database users that we created in the previous article, deltadb. This is the user that we want to delete from our MySQL server. To delete the user we use the DROP command.
DROP USER 'USER'@'HOST';
So, our command to delete the deltadb user would be
DROP USER 'deltadb'@'localhost'; DROP USER 'deltadb'@'%';
Now, if we list all users on the server we can see the deltadb user had been removed.
Delete MySQL Databases
Now we have deleted the MySQL user we also want to delete the database. When you issue the next command all data in the database will be deleted. If you need a copy of the data dump the database before issuing the command to delete.
First, list all of the databases on the MySQL/Mariadb server with
We want to delete the delta and deltadb databases so again, we use the drop command to achieve this.
DROP DATABASE delta; DROP DATABASE deltadb;
That’s the process complete. We have deleted the MySQL user we created in our previous guide and now we have also deleted the MySQL database.
How was this article? How To Delete MySQL Databases & Users From Your MySQL Server