Update WordPress Database After Moving it to new domain name

When you migrate a WordPress installation from one domain to another and thus its hostname changes, you need to update database and make sure the links in your content and page names are all changed to address the new environment.

Here’s 2 simple tricks:

Option 1. Find and replace the hostname in the database dump BEFORE importing it into the new environment.

This is nice and simple if your database is not too big and you have a UTF-8 capable text editor that can handle text-files of several megabytes big.

Simply search for your development hostname “dev-local.somedomain.com” and replace it with the new location’s hostname “www.somedomain.com”.

This way all instances get replaced so this seems like the safest way to do it.

Option 2. Find and replace the hostname in the database AFTER moving it.

If you’ve already made changes to the live database or you just don’t want to go for approach #1 then you can run the queries below.

Make sure to change the wp_ prefix to the one that applies to your installation.

Also note that this will not update any plugin settings etc. It’s still recommended to go through all plugin configuration screens to see if you need to modify something.
Or simply do another search for the old hostname using your Database administration tool of choice.

Modify the following queries to represent the correct values and table names before executing them!

UPDATE wp_options SET option_value = REPLACE(option_value, 'http://dev-local.somedomain.com','http://www.somedomain.com');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://dev-local.somedomain.com','http://www.somedomain.com');
UPDATE wp_posts SET guid = REPLACE(guid, 'http://dev-local.somedomain.com','http://www.somedomain.com');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://dev-local.somedomain.com','http://www.somedomain.com');

 

Posted in Uncategorized | Leave a comment