Skip to content

Instantly share code, notes, and snippets.

@Phlow
Last active May 6, 2020 17:29
Show Gist options
  • Save Phlow/e8f7b3835652af289a31 to your computer and use it in GitHub Desktop.
Save Phlow/e8f7b3835652af289a31 to your computer and use it in GitHub Desktop.
MySQL Queries When Moving WordPress
/*
There's a better tool https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
MySQL Queries When Moving WordPress
To use this snippet, you have to:
1. Change the table prefix according your installation. In the example it's: wp_
2. Change http://old-domain.com to your old domain.
3. Change http://new-domain.com to your new domain.
Please have a close look if you used the domain with or without WWW.
Generator › http://adambalee.com/tools/moving-wordpress-sql-generator.php
Or use a plugin › https://wordpress.org/plugins/duplicator/
*/
UPDATE wp_options SET option_value = replace(option_value, 'http://old-domain.com', 'http://new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://old-domain.com', 'http://new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://old-domain.com', 'http://new-domain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://old-domain.com','http://new-domain.com');
@kanlukasz
Copy link

Don't forget about UPDATE wp_postmeta SET meta_value ..... 😉

@Phlow
Copy link
Author

Phlow commented Mar 2, 2020

@kanlukasz Thank you for telling me! I added it :)

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