Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchelldmiller/83eb4416f68d943b028c to your computer and use it in GitHub Desktop.
Save mitchelldmiller/83eb4416f68d943b028c to your computer and use it in GitHub Desktop.
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