Skip to main content

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

FlagDefaultDescription
TABLE...All tablesSpecific table names to include in output
--scope=SCOPEallFilter: all, global, blog, old
--networkInclude all tables for a multisite network
--all-tables-with-prefixInclude all tables matching the DB prefix
--all-tablesInclude all tables regardless of prefix
--format=FORMATlistOutput 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

TablePurpose
wp_postsPosts, pages, attachments, revisions
wp_postmetaPost metadata (custom fields)
wp_commentsComments
wp_commentmetaComment metadata
wp_termsTags, categories, custom taxonomy terms
wp_term_taxonomyTerm taxonomy mappings
wp_term_relationshipsPost-to-term relationships
wp_termmetaTerm metadata
wp_optionsSite configuration and plugin settings
wp_usersUser accounts
wp_usermetaUser metadata (roles, capabilities, profile data)
wp_linksDeprecated blogroll links

Best Practices

  1. Use --all-tables to discover leftover tables from deactivated plugins.
  2. Always verify tables after import to confirm the dump was complete.
  3. Use output in scripts to dynamically target tables for export or query operations.
  4. Clean up stale tables from removed plugins to reduce DB size.

Troubleshooting

ProblemCauseFix
Fewer tables than expectedTable prefix mismatchUse --all-tables to view all
Extra unexpected tablesPlugin remnantsIdentify and drop orphaned tables
Empty outputWrong WordPress rootUse --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.