Skip to content

MySQL Tutorial Working with Databases

DROP DATABASE

Lesson 30 of 308 2 min read By Deepak Paswan Updated Oct 5, 2026

DROP DATABASE deletes a database and every table, row, view and stored program inside it. There is no recycle bin and no confirmation.

query.sql
SQL
CREATE DATABASE old_project;
CREATE TABLE old_project.users (id INT);
SHOW DATABASES LIKE 'old_project';
DROP DATABASE old_project;
SHOW DATABASES LIKE 'old_project';
Output
OUTPUT
+------------------------+
| Database (old_project) |
+------------------------+
| old_project            |
+------------------------+
1 row in set

Empty set

The first SHOW lists old_project. After the drop, it returns nothing.

IF EXISTS

Dropping something that is not there is an error, unless you add IF EXISTS:

query.sql
SQL
DROP DATABASE missing_db;
Output
OUTPUT
ERROR 1008 (HY000): Can't drop database 'missing_db'; database doesn't exist
query.sql
SQL
DROP DATABASE IF EXISTS missing_db;
SHOW WARNINGS;
Output
OUTPUT
Empty set

IF EXISTS makes scripts that reset a test environment safe to repeat.

What is deleted

  • Every table and its data
  • Views, stored procedures, functions, triggers and events in that database
  • The folder on disk

What is not deleted: user accounts, and privileges are not removed automatically (grants that name the database stay until you revoke them).

It cannot be rolled back

DROP DATABASE is DDL, and DDL commits at once (DDL, DML, DQL, DCL and TCL). The only way back is a backup (Backup and Restore).

A safety checklist

  1. Check the name. SELECT DATABASE();
  2. Look at what is inside. SHOW TABLES FROM name;
  3. Take a backup. Even if you “know” you do not need it.
  4. Use accounts with least privilege. Your web application’s database user must not have DROP rights.
  5. Do not run it in production by hand without a second person checking the name.
query.sql
SQL
CREATE DATABASE temp_check;
CREATE TABLE temp_check.t (id INT);
SELECT table_name FROM information_schema.tables WHERE table_schema = 'temp_check';
DROP DATABASE IF EXISTS temp_check;
Output
OUTPUT
+------------+
| TABLE_NAME |
+------------+
| t          |
+------------+
1 row in set
dangerous
Typing the wrong name
DROP DATABASE shop; and DROP DATABASE shop_backup; look almost the same. Many production incidents begin with a tired person and a similar name. In real systems, restrict DROP to a few accounts and require a backup first.