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

DROP DATABASE

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.

🔒

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.