The DROP DATABASE statement drops all tables in the database and deletes the database permanently.
DROP DATABASE [ IF EXISTS ]
database_name
[,database_name2,...];- If you drop a database that does not exist, MySQL will issue an error.
- To prevent an error from occurring if you delete a non-existing database, you can use the
IF EXISTSoption.
The DROP DATABASE statement returns the number of tables it deleted.
Before deleting a database, you must ensure the following important points:
- First, the
DROP DATABASEstatement deletes the database and also the physical disk files used by the database. Therefore, you should have a backup of the database in case you want to restore it in the future. - Second, you cannot drop the database that is currently being used.
Trying to drop a database currently being used causes the following error:
Cannot drop database "database_name" because it is currently in use.The following example uses the DROP DATABASE statement to delete the TestDb database:
DROP DATABASE IF EXISTS TestDb;