wp-cli-rename-db-prefix icon indicating copy to clipboard operation
wp-cli-rename-db-prefix copied to clipboard

Easier / faster way or bad idea?

Open erus00 opened this issue 5 years ago • 0 comments

Hi,

What would you think of a simple script like this one? Wouldn't it be easier or am I being too simplistic using sed?

$SITE_B_DB, $SITE_B_USER, PREFIX1, PREFIX2, SITE_B would need to be replaced in the script.

wp --allow-root db export /tmp/export1.sql # Export DB
sudo sed "s/$PREFIX1/PREFIX2/g" /tmp/export1.sql > export2.sql # Replace prefix (make sure it is random like "ds5K6g" so no issue with DB content)

mysql -u root -p'"$var_mysql_password"' -e \"DROP DATABASE $SITE_B_DB; 
mysql -u root -p'"$var_mysql_password"' -e \"CREATE DATABASE $SITE_B_DB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql -u root -p'"$var_mysql_password"' -e \"GRANT ALL ON $SITE_B_DB.* TO '$SITE_B_USER'@'localhost';
mysql -u root -p'"$var_mysql_password"' -e \"FLUSH PRIVILEGES;

wp --allow-root db import /tmp/export2.sql # Import of the DB

sudo sed -i "s/$PREFIX1/$PREFIX2/g" $SITE_B/wp-config.php #Replace the DB name is wp-config

Thanks a lot

erus00 avatar Jul 21 '20 08:07 erus00