Changing WordPress Site URL using raw MySQL Query

At times, you may want to migrate a wordpress installation to another domain. At that point of time, you need to change the website url in the wordpress database to point to the new website url.

1. Change the option values in wp_options table

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-website.com', 'http://www.new-website.com') WHERE option_name = 'home' OR option_name = 'siteurl';

2. Change the guid value (post url) in wp_posts table

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-website.com', 'http://www.new-website.com');

3. Look up and replace the url in post content in wp_posts table

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-website.com', 'http://www.new-website.com');

Popularity: 18% [?]

This entry was posted in Wordpress, Wordpress Hacks. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *