Move WordPress database

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%”;

 

Advertisements

About admin

Just another php developer trying to give something back to the community.
This entry was posted in SQL, Wordpress and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s