Sometimes we need to delete a MySQL database through the 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 privileges 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 the password.

Now, you will be at MySQL prompt and it looks like this :

# mysql>

Now, to delete a database from the server you have to run this command :

# mysql> DROP DATABASE datbase-name; //Syntax
# mysql> DROP DATABASE example_database; //Example

If the database is not present on the server it will show 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

Hasznosnak találta ezt a választ? 0 A felhasználók hasznosnak találták ezt (0 Szavazat)