Here is how to delete MySQL database from Command Line Interface or SSH using MySQL drop database command. It is quite simple and easy. Previously, we have shown how to export WordPress MySQL Database on Rackspace Deployment using only Command Line Interface. MySQL by default has quite powerful interactive interface. PHPMyAdmin is a risk itself if run for production environment. Before the reader is going to delete MySQL database from Command Line, we recommend to take a backup of the whole server although if properly done, this can not be a risk to other databases.
Commands to Delete MySQL Database From Command Line
For example, in the guide for installing Piwik on nginx on Ubuntu 14.04 on Rackspace Cloud, we really installed Piwik on production environment and understood it is far from our expectation. Only recursively deleting the web software is not a good idea for security reasons. If you have old MySQL database, make sure the name is correct. References can be found here :
1 |
http://dev.mysql.com/doc/refman/5.0/en/drop-database.html |
---
First, SSH to the database server as server’s root user. MySQL root user might have different password. This command to login to MySQL as root usually works fine :
1 2 3 4 5 6 |
mysql -u root -p # you are root, give password # welcome message followed by # mysql interactive mode like this # mysql > # will start |
The syntax to delete MySQL database is :
1 |
DROP {DATABASE | SCHEMA} [IF EXISTS] db_name |
But we will run this to get the list of all databases :
1 2 3 4 5 |
show databases; # will look like mysql > mysql > show databases; # hit return or Enter key |
It will return thing like this :
1 2 3 4 5 6 7 8 9 |
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | your-db-to-delete | | your-another-db | | your-db-to-here | +--------------------+ |
You want to delete that database named your-db-to-delete
; in that case you’ll run :
1 2 3 4 5 6 7 8 9 |
drop database your-db-to-delete; # alternate 1 # drop database your-db-to-delete # alternate 2 # drop schema your-db-to-delete; ## will look like mysql > mysql > drop database your-db-to-delete ## hit return or Enter key |
Again reload the databases :
1 |
show databases; |
And flash the privileges :
1 |
FLUSH PRIVILEGES; |
If you had an user WHO WAS THE ONLY USER OF THAT INTENDED TO DELETE DATABASE, you must delete it too :
1 2 3 4 5 |
drop user user_name; # user_name is variable # like abhishek # like wordpress # like foo |
Again flush the privileges.
Here’s what we’ve got for you which might like :
Additionally, performing a search on this website can help you. Also, we have YouTube Videos.
Take The Conversation Further ...
We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!
If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.
Contact Us