db-command
db-command copied to clipboard
Is it possible to wp db import or wp db export changing the table prefix
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...
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 dbsed --in-place --expression 's#`wp_#`stacked_#g' database-file-2020-05-21-77387c0.sqlsed --in-place --expression 's#'wp_user_roles#'stacked_user_roles#g' database-file-2020-05-21-77387c0.sqlsed --in-place --expression 's#'wp_capabilities#'stacked_capabilities#g' database-file-2020-05-21-77387c0.sqlsed --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.