How to delete MySQL database through command line ?

How to delete MySQL database through command line ?

Sometimes we need to delete a MySQL database through command line. Before deleting a database you must check these points like you must have root access, before use DROP DATABASE you should check you have DROP privilages or not.

First, we will login to the MySQL server through command line :
-----
# mysql -u root -p ******
-----
Here, -u option is for username and -p option is for password.

Now, you will be at MySQL prompt and it looks like this :
-----
# mysql>
-----

Now, to delete a database from server you have to run this command :
-----
# mysql> DROP DATABASE datbase-name; //Syntax
# mysql> DROP DATABASE example_database; //Example

-----

If database is not present on the server it will shows an error like this :
-----
ERROR 1008 (HY000): Can't drop database 'example_database'; database doesn't exist
-----

To avoid this message you can use this command :
-----
# mysql> DROP DATABASE IF EXISTS datbase-name; //Syntax
# mysql> DROP DATABASE IF EXISTS example_database; //Example

-----

To List all MySQL databases you can check our this article too.
Author
bhawanisingh
Views
1,777
First release
Last update
Rating
0.00 star(s) 0 ratings
Top