WP-CLI has some powerful tools built in for database management, here are some of the most used/convenient features.
Note: Please use caution when performing commands on the database and always make sure to make a backup. If you haven't done so yet, please view Using WP-CLI Command Line Tools 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.
wp db export ~/backup_name.sql
Importing a Database
Imports the database .sql file that you indicate.
For more information, take a look at our tutorial on importing databases with WP-CLI.
wp db import new_database.sql
Checking Your Database For Errors
Checks your connection settings and runs the MySQL CHECK TABLE statement.
wp db check
Resetting Your WordPress Database
This will reset the database to a fresh wp_ instance.
wp db reset
Opening a MySQL Client to Perform MySQL Queries
Connects to the database and opens the mysql command line client
wp db query
Exporting an .xml File
Exports the database in .xml/wxr format.
Note: Please see the documentation for handling authors from the wp-cli.org site
Importing an .xml File
Imports the .xml file you indicate.
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
wp search-replace 'http://old-domain.com' 'http://new-domain.com' --all-tables