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 wp-cli.org 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 'http://old-domain.com' 'http://new-domain.com'

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

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

  • Multisite Database Commands
    WP-cli also has powerful commands for working within Multisite. Here are a few that are helpful for working within th...

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-2016 Pagely, Inc. All rights reserved.
Pagely® and WordPress® are registered trademarks.

Pagely
Powered by Zendesk