← Back to MySQL Course | Chapter 2: Databases & Tables | Lesson 2 of 7

DROP DATABASE

DROP DATABASE is like throwing the entire filing cabinet into a bonfire, drawers and papers included. There is no way to get it back.
Syntax
sql
DROP DATABASE [IF EXISTS] database_name;

Deleting a Database

DROP DATABASE permanently deletes the database and every table, row, and index inside it in one irreversible step — there's no built-in undo, so this command deserves the same caution as rm -rf.

Example: Deleting a Database

sql
DROP DATABASE shop;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Safe Database Deletion

Adding IF EXISTS avoids a hard error when the target database is already gone, which matters in automated teardown scripts that might run against an environment in an unknown state.

Example: Safe Database Deletion

sql
DROP DATABASE IF EXISTS shop;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Deleting Custom Schemas

SCHEMA is simply a synonym MySQL accepts for DATABASE, so DROP SCHEMA and DROP DATABASE do exactly the same thing — useful to know since other tools and documentation use the two terms interchangeably.

Example: Deleting Custom Schemas

sql
DROP SCHEMA IF EXISTS shop;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Cleaning Up Test Systems

Dropping and recreating a database is a common way to reset a test or staging environment to a known-clean state, wiping out any accumulated test data or schema drift from previous runs.

Example: Cleaning Up Test Systems

sql
DROP DATABASE IF EXISTS test_env;
CREATE DATABASE test_env;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Verifying Deletion

After dropping, running SHOW DATABASES confirms the name no longer appears in the list — a cheap sanity check before assuming an automated cleanup script actually succeeded.

Example: Verifying Deletion

sql
SHOW DATABASES;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Running DROP DATABASE shop; on the wrong server or without a backup, which permanently deletes every table in it.
  2. Forgetting IF EXISTS in a script, so it stops with an error when the database is missing.
  3. Trying to drop the database you are currently using and then running queries without a USE.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.