DROP DATABASE
In this page:
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
DROP DATABASE shop;
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
DROP DATABASE IF EXISTS shop;
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
DROP SCHEMA IF EXISTS shop;
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
DROP DATABASE IF EXISTS test_env;
CREATE DATABASE test_env;
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
SHOW DATABASES;
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: