Skip to content

Instantly share code, notes, and snippets.

@mrlinnth
Forked from vunb/wordpress-change-domain-migration.sql
Last active October 31, 2025 00:57
Show Gist options
  • Select an option

  • Save mrlinnth/18722b553cc83eb3c85b98b06795a668 to your computer and use it in GitHub Desktop.

Select an option

Save mrlinnth/18722b553cc83eb3c85b98b06795a668 to your computer and use it in GitHub Desktop.
Wordpress domain change sql script

Use this SQL script when changing domains on a WordPress site. Whether you’re moving from an old domain to a new domain or you’re changing from a development domain to a production domain this will work.

  1. always backup your database.
  2. change the ‘oldsite.com’ and ‘newsite.com’ variables to your own.
  3. make sure your database prefix is “wp_”, if it’s not then you’ll want to go through and change the prefix in each line to whatever yours is.
  4. copy the modified variables and the queries and paste it into phpMyAdmin or, better yet, SequelPro and run it on your database. TEST. DONE.

Changelog: — updated queries to use variables instead of editing the urls in many different areas — commented out GUID and left as optional. shouldn’t reset those.

ref: codex.wordpress.org/Changing_The_Site_URL#Important_GUID_Note

SET @oldsite='http://oldsite.com';
SET @newsite='http://newsite.com';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);
/* only uncomment next line if you want all your current posts to post to RSS again as new */
#UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment