db-command icon indicating copy to clipboard operation
db-command copied to clipboard

Is it possible to wp db import or wp db export changing the table prefix

Open kevinmamaqi opened this issue 5 years ago • 1 comments

In my workflow I rsync and use wp cli via SSH to import/export the database and then do a search-replace to update the URLs, etc... While it works perfectly I am forced to use the same DB prefix, is it possible to change it dynamically when exporting or importing using wp cli? Perhaps wp config update table prefix...

kevinmamaqi avatar Jan 11 '20 17:01 kevinmamaqi

I don't know how to do this solely using WP-CLI however here is one way to accomplish this using WP-CLI and sed. For this example I'll export a database with prefix wp_ then change it to stacked_ within the .sql file itself.

  • wp export db
  • sed --in-place --expression 's#`wp_#`stacked_#g' database-file-2020-05-21-77387c0.sql
  • sed --in-place --expression 's#'wp_user_roles#'stacked_user_roles#g' database-file-2020-05-21-77387c0.sql
  • sed --in-place --expression 's#'wp_capabilities#'stacked_capabilities#g' database-file-2020-05-21-77387c0.sql
  • sed --in-place --expression 's#'wp_user_level#'stacked_user_level#g' database-file-2020-05-21-77387c0.sql

The wp config command will only make adjustments to your wp-config.php file. It doesn't make changes to the database.

austinginder avatar Oct 16 '20 01:10 austinginder