Topic in WP-CLI

WP-CLI Database Commands

Last Updated -


WP-CLI has some powerful tools built in for database management, here are some of the most used/convenient features. (If you haven't done so please view Using WP-CLI Command Line Tools first)

Note: Please use caution when performing commands on the database and always make sure to take a backup first.

Backing Up Your Database

Exports a .sql dump into your site directory.

For more information on creating database backups with WP-CLI, take a look at our tutorial on exporting databases with WP-CLI.

Example

wp db export backup_name.sql

Importing a New .sql Dump

Imports the database .sql file that you indicate.

For more information, take a look at our tutorial on importing databases with WP-CLI.

Example

wp db import new_database.sql

Truncating Your Database Tables and Dropping Tables Without the wp_ Prefix

This will reset the database to a fresh wp_ instance.

Example

wp db reset

 

Opening a MySQL Client to Perform MySQL Queries

Connects to the database and opens the mysql command line client

Example

wp db query

Exporting a .xml File

Exports the database in .xml/wxr format.

Note: Please see the documentation for handling authors from the wp-cli.org site

Example

wp export

Importing a .xml File

Imports the .xml file you indicate.

Example

wp import filename.xml

Search and Replace

Performs a search and replace function on the database that also handles serialized arrays.

The --all-tables flag will update tables that don't have the same table prefix that is used by WordPress.

You can also use --precise which uses PHP and is a bit more thorough but it takes longer so it should be used after the first process did not correct everything. Please consider cache on the server and in your local browser before using that though.

Note: Multi-site should use this article

Example

wp search-replace 'http://old-domain.com' 'http://new-domain.com' --all-tables

 

Related Topics

  • Using WP-CLI Command Line Tools
    All VPS and Enterprise plans come with a powerful command line tool known as WP-CLI. For an overview of basic command...

  • WP-CLI Database Commands
    WP-CLI has some powerful tools built in for database management, here are some of the most used/convenient features. ...

  • Multisite Database Commands
    NOTE: These commands are for subfolder multisite only. If you are using multiple domains in your sub sites please con...

Pagely is the Managed WordPress Hosting Platform designed to exceed the needs of media, business, and Enterprise customers alike. We help the world's biggest brands scale WordPress.

Copyright © 2006-2017 Pagely, Inc. All rights reserved.
Pagely® and WordPress® are registered trademarks.

Pagely
Powered by Zendesk