Topic in WP-CLI

WP-CLI Database Commands

Last Updated -

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

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)

Backing up your database

$ wp db export backup_name.sql

 Exports a .sql dump into your site directory

Truncating your database tables and dropping tables without the wp_ prefix

$ wp db reset

 This will reset the database to a fresh wp_ instance

Importing a new .sql dump

$ wp db import new_database.sql

 Imports the database .sql file you indicate

Opening mysql client to perform mysql queries

$ wp db query

 Connects to the database and opens the mysql command line client

Exporting a .xml file Note: Please see the documentation for handling authors from the site

$ wp export

 Exports the database in .xml/wxr format

Importing a .xml file

$ wp import filename.xml

 Imports the .xml file you indicate

Search and Replace

NOTE: Mult-site should use this article

 wp search-replace '' '' --all-tables

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.

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
    Note: Please use caution when performing commands on the database and always make sure to take a backup first. WP-CLI...

  • 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.

Powered by Zendesk