Move WordPress Database

Posted on the 08 July 2014 by Akahgy

Description:

Moving an existing WordPress database is the easiest solution for changing website domain, duplicating content and so on, when we don’t want to lose posts, configurations and other meta data. However, this brings along also the connection to the former parent url, and that might cause issues with wp-admin and other internal paths.

Solution:

WordPress maintains home and siteurl information in the options database table, which can be updated so:

select * from wp_options where option_name = ‘siteurl’\G;

UPDATE wp_options set option_value = ‘http://new-website’ where option_name = ‘siteurl’;

select * from wp_options where option_name = ‘home’\G;

UPDATE wp_options set option_value = ‘http://new-website’ where option_name = ‘home’;

Then, all urls will point to the new site. To set the guid of imported posts, just update -replace the url in the posts:

UPDATE wp_posts SET guid = REPLACE(guid, “http://old-site”, “http://new-site”) WHERE guid LIKE “%http://old-site%”;