Skip to content

Instantly share code, notes, and snippets.

@thewatts
Created October 14, 2012 06:00
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 thewatts/3887543 to your computer and use it in GitHub Desktop.
Save thewatts/3887543 to your computer and use it in GitHub Desktop.
Snippets to use with AlfredApp to import your production database into your local database, and then change your production URL values to your local URL values in WordPress.
-- This file will be used in the snippet below.
-- This is the name of your local database
USE local_db
-- Replacing all instances of your production URL with your local URL
UPDATE wp_options SET option_value = replace(option_value, 'http://sitename.com', 'http://sitename.local')
WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, 'http://sitename.com', 'http://sitename.local');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://sitename.com', 'http://sitename.local');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://sitename.com','http://sitename.local');
# Dump Production DB
/Applications/MAMP/Library/bin/mysqldump -h host_server_ip -u username -p'password' production_db_name > ~/path/to/production_dump.sql
#Import to Local server
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot local_db < ~/path/to/production_dump.sql
#Change the URL values
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot local_db < ~/path/to/db_prod2local_alfredapp.sql
echo "BOOM! DB IMPORTED PRODUCTION DATABASE TO LOCAL ENVIRONMENT."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment