Last active
December 21, 2020 10:26
-
-
Save NickHatBoecker/b65694a4bd756a80baef6741a62358c9 to your computer and use it in GitHub Desktop.
Moving Wordpress: Update SQL Statements
This file contains 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 | |
# | |
# This script is used to update database url entries for wordpress. | |
# | |
# © Nick Böcker <https://nick-hat-boecker.de> 2019 | |
# User input mysql username | |
read -p "Enter mySQL username [root]: " USER | |
USER=${USER:-root} | |
# User input mysql database | |
read -p "Enter database name: " DATABASE | |
# User input mysql database prefix | |
read -p "Enter database prefix [wp_]: " PREFIX | |
PREFIX=${PREFIX:-wp_} | |
# User input mysql new and old url | |
read -p "Enter old url: " OLD_URL | |
read -p "Enter new url: " NEW_URL | |
# Execute command with given credentials and parameters. Ask for password. | |
mysql -p --user="$USER" --database="$DATABASE" --execute="UPDATE ${PREFIX}posts SET guid = REPLACE(guid, '${OLD_URL}', '${NEW_URL}'); UPDATE ${PREFIX}posts SET post_content = REPLACE(post_content, '${OLD_URL}', '${NEW_URL}');UPDATE ${PREFIX}postmeta SET meta_value = REPLACE(meta_value, '${OLD_URL}', '${NEW_URL}'); UPDATE ${PREFIX}options SET option_value = REPLACE(option_value, '${OLD_URL}', '${NEW_URL}');" | |
echo 'Done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment