wp db tables
Overview
List every table in the WordPress database. Use it to understand the full DB structure, verify plugin tables exist, audit leftovers from removed plugins, or target specific tables for export and query operations.
What It Does
wp db tables queries the MySQL SHOW TABLES and returns all tables within the WordPress database. Results can be filtered by scope (global/blog) and output in multiple formats for scripting.
Syntax
wp db tables [<table>...] [--scope=<scope>] [--network] [--all-tables-with-prefix] [--all-tables] [--format=<format>]
Options & Flags
| Flag | Default | Description |
|---|---|---|
TABLE... | All tables | Specific table names to include in output |
--scope=SCOPE | all | Filter: all, global, blog, old |
--network | — | Include all tables for a multisite network |
--all-tables-with-prefix | — | Include all tables matching the DB prefix |
--all-tables | — | Include all tables regardless of prefix |
--format=FORMAT | list | Output format: list, csv |
Basic Usage
List all tables
wp db tables
Output:
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_term_relationships
wp_term_taxonomy
wp_termmeta
wp_terms
wp_usermeta
wp_users
CSV output
wp db tables --format=csv
List only global (non-blog) tables in multisite
wp db tables --scope=global
List all tables including non-WP tables
wp db tables --all-tables
Real-World Scenarios
Scenario 1: Audit leftover tables from removed plugins
# List all tables
wp db tables --all-tables-with-prefix
# Compare against expected core tables
# Anything not in the core list is from plugins
# Remove with: wp db query "DROP TABLE IF EXISTS wp_abandoned_plugin_table;"
Scenario 2: Export only core WordPress tables (exclude plugin tables)
CORE_TABLES=$(wp db tables --scope=blog --format=csv)
wp db export core_only.sql --tables="${CORE_TABLES}"
Scenario 3: Verify tables exist after import
wp db import dump.sql
# Check expected tables are present
EXPECTED=("wp_posts" "wp_users" "wp_options")
for table in "${EXPECTED[@]}"; do
if wp db tables | grep -q "^${table}$"; then
echo "✅ ${table} exists"
else
echo "❌ ${table} MISSING"
fi
done
Scenario 4: Multisite — list all network tables
wp db tables --network --scope=all --format=csv
Scenario 5: Count total tables
TOTAL=$(wp db tables | wc -l)
echo "Total tables: ${TOTAL}"
WordPress Core Table Reference
| Table | Purpose |
|---|---|
wp_posts | Posts, pages, attachments, revisions |
wp_postmeta | Post metadata (custom fields) |
wp_comments | Comments |
wp_commentmeta | Comment metadata |
wp_terms | Tags, categories, custom taxonomy terms |
wp_term_taxonomy | Term taxonomy mappings |
wp_term_relationships | Post-to-term relationships |
wp_termmeta | Term metadata |
wp_options | Site configuration and plugin settings |
wp_users | User accounts |
wp_usermeta | User metadata (roles, capabilities, profile data) |
wp_links | Deprecated blogroll links |
Best Practices
- Use
--all-tablesto discover leftover tables from deactivated plugins. - Always verify tables after import to confirm the dump was complete.
- Use output in scripts to dynamically target tables for export or query operations.
- Clean up stale tables from removed plugins to reduce DB size.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Fewer tables than expected | Table prefix mismatch | Use --all-tables to view all |
| Extra unexpected tables | Plugin remnants | Identify and drop orphaned tables |
| Empty output | Wrong WordPress root | Use --path=/var/www/html |
Quick Reference
wp db tables # List all tables
wp db tables --format=csv # CSV format
wp db tables --scope=global # Global tables only
wp db tables --all-tables # All DB tables regardless of prefix
wp db tables | wc -l # Count tables
Next Steps
wp db export— use table list to target specific tables for export.wp db query— run SQL against discovered tables.wp db size— check the size of these tables.