Blog

Awesome SQL queries for WordPress Migration

Posted on: 05 May 2015     Posted by: Freesize Workroom
Categories: Wordpress

Use the following queries to change the domain of a WordPress site:

 

/* Change Siteurl & Homeurl */
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';

/* Change GUID */
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com');

/* Change URL in Content */
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com');

/* Change Image Path Only */
UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="http://www.oldsiteurl.com', 'src="http://yourcdn.newsiteurl.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.oldsiteurl.com','http://www.newsiteurl.com');

/* Update Post Meta */
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.oldsiteurl.com','http://www.newsiteurl.com');

In the most cases, the three queries above should get your WordPress site up and running on the new domain URL. If you are able to access home page but not the sub pages on the new domain name, simply just login into the WordPress admin and update the permalink. The subpages should be up and running after the update of the permalink.

If you need other changes, for example like update the admin password, refer to the article below.

SQL Queries reference from:

http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

Leave a Reply

Your email address will not be published.