MySQL - DROP DATABASE Statement



MySQL DROP DATABASE Statement

You can drop/delete an existing database using the DROP DATABASE Statement.

Syntax

Following is the syntax of the DROP DATABASE statement −

DROP DATABASE database_name;

Where, database_name is the name of the database you need to delete.

Example

Suppose we have created databases as shown below −

CREATE DATABASE testDB1;
CREATE DATABASE testDB2;
CREATE DATABASE testDB3;
CREATE DATABASE testDB4;

If you verify the list of databases you can observe the created ones in the list as follows −

show databases;

Output

The above mysql query will genrate the following output −

Database
information_schema
mydatabase
performance_schema
testdb1
testdb2
testdb3
testdb4
world

You can delete three of the above created databases using the DROP DATABASE statement as shown below −

DROP DATABASE testDB1;
DROP DATABASE testDB2;
DROP DATABASE testDB3;

Make sure you have the admin privilege before dropping any database. Once a database is dropped, if you can verify the list of the tables as shown below you can see its name is missing −

show databases;

Output

Following is the output of the above query −

Database
information_schema
mydatabase
performance_schema
testdb4
world
Advertisements