How do I remove a MySQL database?


To remove any database, we need to use DROP command in MySQL. Here is the syntax.

DROP DATABASE yourDatabaseName;

First, let us check how many databases are present in MySQL. Here is the query for the same.

mysql> SHOW DATABASES;

The following is the output.

+--------------------+
| Database           |
+--------------------+
| business           |
| database1          |
| databasesample     |
| education          |
| hello              |
| information_schema |
| javadatabase       |
| javadatabase2      |
| javasampledatabase |
| mybusiness         |
| mydatabase         |
| mysql              |
| performance_schema |
| sample             |
| sampledatabase     |
| schemasample       |
| sys                |
| test               |
| test3              |
| universitydatabase |
+--------------------+
20 rows in set (0.00 sec)

As displayed above, we have total 20 databases in MySQL. Here, let us try to remove database ‘javadatabase’.

The following is the query to remove database.

mysql> DROP DATABASE javadatabase;
Query OK, 0 rows affected (0.19 sec)

We have successfully removed the “javadatabase”. To verify, let us check with the help of SHOW command.

mysql> show databases;

The following is the output.

+--------------------+
| Database           |
+--------------------+
| business           |
| database1          |
| databasesample     |
| education          |
| hello              |
| information_schema |
| javadatabase2      |
| javasampledatabase |
| mybusiness         |
| mydatabase         |
| mysql              |
| performance_schema |
| sample             |
| sampledatabase     |
| schemasample       |
| sys                |
| test               |
| test3              |
| universitydatabase |
+--------------------+
19 rows in set (0.00 sec)

The above output displays 10 databases now i.e. we have successfully removed the “javadatabase”. Now, you can’t find any database with the name “javadatabase”.

Updated on: 30-Jul-2019

241 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements