iandunn / wp-cli-rename-db-prefix

A WP-CLI command to rename WordPress' database prefix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Easier / faster way or bad idea?

erus00 opened this issue · 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