Name

DROP DATABASE

Synopsis

DROP DATABASE [IF EXISTS] database

Use this statement to delete a given database along with all its tables and data. The addition of the IF EXISTS flag suppresses an error message if the database does not already exist:

DROP DATABASE IF EXISTS test;
Query OK, 6 rows affected (0.42 sec)

Notice that the number of tables deleted is returned in the rows affected count. If the database doesn’t exist or if there are other files in the database’s filesystem directory, an error message will be displayed. The tables will be deleted if other files exist, but the foreign file and the directory won’t be removed. They will have to be deleted manually at the command line using a filesystem command such as rm in Unix or del in Windows.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.