Skip to content

Instantly share code, notes, and snippets.

@richardtape
Created September 14, 2017 01:06
Show Gist options
  • Save richardtape/8ced4552f40fda097d6a171a6532a206 to your computer and use it in GitHub Desktop.
Save richardtape/8ced4552f40fda097d6a171a6532a206 to your computer and use it in GitHub Desktop.
wp-cli with sharded databases
# Be *very* careful with this.
# In your wp-config.php file
$db_name = getenv( 'WP_CLI_DB_NAME' );
define( 'DB_NAME', ( !empty( $db_name ) ? $db_name : 'default_global' ) ); # Default often 'wpmu_global'
# Then, when calling wp-cli, if the tables you want are in a shard called prefix_3f
# And you want to grab the comments table for a site with an ID of 10175
WP_CLI_DB_NAME=prefix_3f; export WP_CLI_DB_NAME; wp db export --tables=wp_10175_comments
@richardtape
Copy link
Author

As an addition here, for certain wp-cli commands, such as wp db tables you'll also need to include the --url flag which needs to point at one of the sites that is run from the tables in the shard you're after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment