wp db create
Overview
Create the MySQL database defined in wp-config.php from the command line. Part of the minimal WordPress provisioning sequence: wp config create → wp db create → wp core install.
What It Does
wp db create reads the DB_NAME (and optionally DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET, DB_COLLATE) from wp-config.php and runs CREATE DATABASE IF NOT EXISTS on the MySQL server. No need to log into MySQL manually.
Syntax
wp db create [--dbuser=<value>] [--dbpass=<value>]
Options & Flags
| Flag | Description |
|---|---|
--dbuser=VALUE | Override DB user from wp-config.php |
--dbpass=VALUE | Override DB password |
Basic Usage
Create the database
wp db create
Output on success:
Success: Database created.
If database already exists:
ERROR 1007 (HY000): Can't create database 'wpdb'; database exists
Error: Cannot proceed, as the database 'wpdb' exists.
Prerequisites
wp-config.php must exist with valid DB connection details before running this command:
# Correct provisioning order:
wp core download
wp config create --dbname=mydb --dbuser=wpuser --dbpass=secret
wp db create # ← this step
wp core install ...
Real-World Scenarios
Scenario 1: Full fresh install pipeline
#!/bin/bash
cd /var/www/html
wp core download --locale=en_US
wp config create \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASS}" \
--dbhost="${DB_HOST:-localhost}"
wp db create
wp core install \
--url="${SITE_URL}" \
--title="${SITE_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASS}" \
--admin_email="${ADMIN_EMAIL}" \
--skip-email
Scenario 2: Docker container initialization
# entrypoint.sh
if ! wp core is-installed --allow-root 2>/dev/null; then
wp config create --dbname=wp --dbuser=root --dbpass=secret --dbhost=db --skip-check
wp db create
wp core install --url=http://localhost --title=DevSite \
--admin_user=admin --admin_password=admin --admin_email=dev@localhost --skip-email
fi
Scenario 3: Staging environment creation
# Read from config file
wp config create --dbname=staging_wp --dbuser=stg_user --dbpass=stg_pass --dbhost=127.0.0.1
wp db create
echo "Staging DB 'staging_wp' created ✅"
Best Practices
- Always create
wp-config.phpfirst —wp db createreads credentials from it. - Use a dedicated DB user per site — not the MySQL root user.
- Verify the DB was created with
wp db tablesorwp db sizeafter creation. - Use
IF NOT EXISTSsemantics are built in — the command is idempotent when the DB already exists (it will warn, not crash silently).
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Access denied | MySQL user lacks CREATE privilege | Grant CREATE to the DB user |
| Database already exists error | Re-running provisioning script | Skip with a conditional: wrap in wp db check or wp core is-installed |
No wp-config.php found | Running from wrong directory | cd /var/www/html first |
Quick Reference
wp db create # Create DB from wp-config.php
wp db drop # Delete DB (destructive)
wp db reset # Drop + recreate all tables
Next Steps
wp core install— run the WordPress installer after creating the DB.wp db tables— verify the database was created correctly.wp db drop— drop the database when decommissioning a site.