Created
June 4, 2019 18:41
-
-
Save mouradev/b4fc799d5cf8e2a195d7644cc0aba232 to your computer and use it in GitHub Desktop.
This script can help you to replace a Wordpress site url in the database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bash script written by Lucas Moura mouradev.com | |
mysql_host="localhost" | |
read -p "Please enter the MySQL root user: " db_user | |
read -p "Please enter root user MySQL password: " root_password | |
read -p "Please enter the database name: " db_name | |
read -p "Please enter the database prefix (blank to no prefix): " db_prefix | |
echo "" | |
read -p "Do you want to run Wordpress url sql replace? (y/n) " sql_replace | |
if [ "$sql_replace" != "${sql_replace#[Yy]}" ] ;then | |
read -p "Please enter the old url (with 'http://'): " old_url | |
read -p "Please enter the NEW url (with 'http://'): " new_url | |
echo "Running sql replace..." | |
mysql -u${db_user} -p${root_password} ${db_name} -e "UPDATE ${db_prefix}options SET option_value = replace(option_value, '${old_url}','${new_url}') WHERE option_name = 'home' OR option_name = 'siteurl';UPDATE ${db_prefix}posts SET guid = replace(guid, '${old_url}','${new_url}');UPDATE ${db_prefix}posts SET post_content = replace(post_content, '${old_url}', '${new_url}');UPDATE ${db_prefix}postmeta SET meta_value = replace(meta_value, '${old_url}', '${new_url}');" | |
fi | |
echo "Your database is ready :)" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do not forget to give execute permission to this file
chmod +x sql_replace.sh