Skip to content

Instantly share code, notes, and snippets.

@ammist
Created August 31, 2011 07:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ammist/1183000 to your computer and use it in GitHub Desktop.
Save ammist/1183000 to your computer and use it in GitHub Desktop.
MySQL Wrangling
-- handy for moving a database from prouction to your local environment.
-- change URL's in wordpress single-site install. Replace with your own URL's.
-- this doesn't address serialized options.
UPDATE wp_options SET option_value = "http://localhost:8888" WHERE option_name = "home";
UPDATE wp_options SET option_value = "http://localhost:8888" WHERE option_name = "siteurl";
update wp_postmeta set meta_value = replace(meta_value, 'http://example.com', 'http://localhost:8888') where meta_key='_menu_item_url';
update wp_posts set post_content = replace(post_content, 'http://example.com', 'http://localhost:8888');
-- Export a mysql database from the commandline:
-- That chararacter set stuff isn't always needed (most SQL databases are
mysqldump [database] --opt -u [username] --password='[password]' --default-character-set=latin1 -N > [filename]
@ammist
Copy link
Author

ammist commented Aug 31, 2011

I use this to create a backup script on my development environment. Whenever I make a major change to a database, I like to back it up first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment