Show Menu
Cheatography

WP-CLI Database Functions Cheat Sheet by

Database functions for the Wordpress command line interface

Inform­ational

wp db check
check the current status of the database
wp db size
display the database name and size
wp db prefix
display the database table prefix
wp db tables
lists the database tables
wp db columns
display inform­ation about a given table

Manipu­lation

wp db import
imports a database
wp db export
exports the database
wp db search
finds a string in the database
wp db query
executes a SQL query
# Execute a query stored in a file
$ wp db query < debug.sql

# Execute a query from prompt
$ wp db query '<q­uer­y>'
 

DB Functions

 
This sheet is a quick reference of the commands available to operate with and manipulate within a Wordpress database using
wp-cli
.

EXAMPLES

 
# Create a new database.
$ wp db create
Success: Database created.

# Drop an existing database.
$ wp db drop --yes
Success: Database dropped.

# Reset the current database.
$ wp db reset --yes
Success: Database reset.

# Execute a SQL query stored in a file.
$ wp db query < debug.sql
 

Operations

wp db cli
open a MySQL console
wp db create
create a new database
wp db drop
drop an existing database
wp db reset
reset the current database
OPTIONS
(create, drop, reset)
[--dbu­ser­=<v­alu­e>]
pass username to mysql
Defaults to DB_USER
[--dbp­ass­=<v­alu­e>]
pass password to mysql
Defaults to DB_PAS­SWORD
[--yes]
avoid confir­mation message
wp db optimize
optimizes the database
wp db repair
repairs the database

Quick Help

wp db <su­bco­mma­nd> help
lists all options
This will provide further options and parameters available for the command and subcommand specified. The technique is applicable throughout the wp-cli.
               
 

Comments

Very useful!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          MySQL Cheat Sheet
          Essential MySQL Cheat Sheet
          PHP Syntax for beginners Cheat Sheet