Skip to main content

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

FlagDescription
--yesSkip the confirmation prompt (required for non-interactive use, e.g. scripts)
--dbuser=VALUEOverride DB user
--dbpass=VALUEOverride 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

  1. ALWAYS export first — run wp db export and confirm the file is valid before dropping.
  2. Never use --yes in production without a guard (confirmation prompt or explicit approval step).
  3. Use in pipelines only in controlled environments (local dev, CI test runners, disposable staging).
  4. Prefer wp db reset when you want to clear tables but keep the database.

Comparison: Drop vs Reset vs Export+Import

GoalCommand
Permanently delete the entire databasewp db drop --yes
Delete all tables but keep the DBwp db reset --yes
Wipe and reload from a dumpwp db drop --yes && wp db create && wp db import dump.sql

Troubleshooting

ProblemCauseFix
Access deniedDB user lacks DROP privilegeGrant DROP to the DB user
Prompt skipped unexpectedlyRunning in a non-TTY terminalUse --yes explicitly
Unknown database after dropDB already didn't existCommand 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