wp db drop
Overview
Permanently delete the WordPress database. A destructive, irreversible operation — always take a backup first. Used for cleanup, decommissioning, or resetting an environment from scratch.
What It Does
wp db drop executes DROP DATABASE using the credentials from wp-config.php. All tables, data, and the database itself are permanently removed. There is no undo.
Syntax
wp db drop [--yes] [--dbuser=<value>] [--dbpass=<value>]
Options & Flags
| Flag | Description |
|---|---|
--yes | Skip the confirmation prompt (required for non-interactive use, e.g. scripts) |
--dbuser=VALUE | Override DB user |
--dbpass=VALUE | Override DB password |
Basic Usage
Interactive drop (prompts for confirmation)
wp db drop
Are you sure you want to drop the 'wpdb' database? [y/n] y
Success: Database dropped.
Non-interactive (scripts, CI/CD)
wp db drop --yes
This is permanent
wp db drop removes the entire database — all tables, posts, users, options, and custom data. There is no recovery unless you have a backup.
Real-World Scenarios
Scenario 1: Environment teardown and rebuild
# Export first — always
wp db export backup_final_$(date +%Y%m%d).sql
# Tear down
wp db drop --yes
# Rebuild
wp db create
wp core install \
--url="${SITE_URL}" \
--title="${SITE_TITLE}" \
--admin_user=admin \
--admin_password=Admin1234! \
--admin_email=admin@example.com \
--skip-email
Scenario 2: CI/CD test cleanup
# After test run — clean up test DB
wp db drop --yes
echo "Test database cleaned up"
Scenario 3: Reset a staging environment
# Drop staging DB and reload from production dump
wp db drop --yes
wp db create
wp db import production_dump.sql
wp search-replace 'https://example.com' 'https://staging.example.com'
Scenario 4: Guarded drop in automation
#!/bin/bash
echo "Creating backup before drop..."
wp db export pre_drop_$(date +%Y%m%d%H%M).sql
read -p "Are you absolutely sure you want to drop the database? (type 'DROP'): " confirm
if [ "$confirm" = "DROP" ]; then
wp db drop --yes
echo "Database dropped."
else
echo "Aborted."
fi
Best Practices
- ALWAYS export first — run
wp db exportand confirm the file is valid before dropping. - Never use
--yesin production without a guard (confirmation prompt or explicit approval step). - Use in pipelines only in controlled environments (local dev, CI test runners, disposable staging).
- Prefer
wp db resetwhen you want to clear tables but keep the database.
Comparison: Drop vs Reset vs Export+Import
| Goal | Command |
|---|---|
| Permanently delete the entire database | wp db drop --yes |
| Delete all tables but keep the DB | wp db reset --yes |
| Wipe and reload from a dump | wp db drop --yes && wp db create && wp db import dump.sql |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Access denied | DB user lacks DROP privilege | Grant DROP to the DB user |
| Prompt skipped unexpectedly | Running in a non-TTY terminal | Use --yes explicitly |
Unknown database after drop | DB already didn't exist | Command may error — this is not a real issue |
Quick Reference
wp db drop # Interactive (prompts)
wp db drop --yes # Non-interactive
wp db export dump.sql && wp db drop --yes # Safe export then drop
Next Steps
wp db create— recreate the database after dropping.wp db export— always export before dropping.wp db reset— clear all tables without dropping the database.