Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import production WordPress database to localhost without plugin update error
#! /bin/bash
# import_wordpress_db_to_localhost.sh
#
# Easy to use to with multiple sites.
# Try:
# alias import_blog='import_wordpress_db_to_localhost.sh DB SQL user password'
#
if [ ! -z $1 ] && [ ! -z $2 ] && [ ! -z $3 ] && [ ! -z $4 ] && [ -f $2 ]; then
echo "Updating $1 with $2 and local settings"
# import database
mysql -u$3 -p$4 -AD $1 < $2
# clear plugins
mysql -u$3 -p$4 -AD $1 -e "update wp_options set option_value = 'a:0:{}' where option_name = 'active_plugins';"
# add "LOCAL : " to site name
mysql -u$3 -p$4 -AD $1 -e "update wp_options set option_value = concat('LOCAL: ', option_value) where option_name = 'blogname';"
# make blog private
mysql -u$3 -p$4 -AD $1 -e "update wp_options set option_value = 0 where option_name = 'blog_public';"
else
echo "Usage: import [DB] [SQL] [USER] [PASSWORD]";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.