HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

MySQL DROP DATABASE

The DROP DATABASE statement permanently deletes an entire database from the MySQL server — including every table, every row of data, and all other objects stored inside it. Once dropped, the database and all its contents are gone and cannot be recovered unless you have a backup.

Warning: DROP DATABASE is irreversible. Always double-check the database name before running this command, and make sure you have a backup if the data is important.

Syntax

DROP DATABASE database_name;

Replace database_name with the exact name of the database you want to delete. MySQL will immediately remove the database and all its contents.


Basic Example

The following statement permanently deletes the database named school:

DROP DATABASE school;

If successful, MySQL responds with:

Query OK, 0 rows affected (0.02 sec)

The database school — along with every table and record inside it — is now completely removed from the server.


Using IF EXISTS

If you try to drop a database that does not exist, MySQL throws an error:

DROP DATABASE school;
-- ERROR 1008 (HY000): Can't drop database 'school'; database doesn't exist

To handle this gracefully — particularly in cleanup scripts — use the IF EXISTS option:

DROP DATABASE IF EXISTS school;

With IF EXISTS, MySQL will only drop the database if it actually exists. If it does not, MySQL issues a warning instead of an error, and the script continues running without interruption.

Best Practice: Use DROP DATABASE IF EXISTS in setup and teardown scripts. This way, your scripts are safe to run repeatedly, whether or not the database currently exists.

DROP SCHEMA — An Alias

In MySQL, the words DATABASE and SCHEMA mean the same thing and can be used interchangeably. So the following two statements are completely identical:

DROP DATABASE school;
DROP SCHEMA school;

Both delete the same database. You will encounter SCHEMA terminology more often in MySQL Workbench and in database design contexts.


What Gets Deleted?

When you drop a database, MySQL removes everything inside it permanently:

  • All tables and the data stored in them
  • All views defined in the database
  • All stored procedures and stored functions
  • All triggers associated with the database
  • All indexes defined on the tables
Good Habit: Before dropping a database in a production environment, always run SHOW DATABASES; to confirm the exact name, and export a backup using mysqldump just in case.

Key Points to Remember

  • DROP DATABASE name; permanently deletes the database and all its contents.
  • This action is irreversible — there is no undo.
  • Use IF EXISTS to prevent errors when the database may not exist.
  • DROP SCHEMA is an alias for DROP DATABASE — they do the same thing.
  • Always verify the database name and back up important data before dropping.