Menu
Menu
November 25, 2010

Moving a WordPress database

Categories: 
Published: 25 November 2010 

Here is a simple SQL statement to run on a WordPress database to move it from one domain name to another

/*
// Simply change the 2 variables below.
// If your blog runs over HTTPS you will also need to change this in the last 2 lines.
*/

SET @oldDomain = 'www.olddomain.com.au';
SET @newDomain = 'www.newdomain.com.au';

update wp_posts
SET guid = REPLACE(guid, @oldDomain,@newDomain)
WHERE guid REGEXP @oldDomain;

update wp_posts
SET post_content = REPLACE(post_content, @oldDomain,@newDomain)
WHERE post_content REGEXP @oldDomain;

update wp_postmeta
SET meta_value = REPLACE(meta_value, @oldDomain,@newDomain)
WHERE meta_value REGEXP @oldDomain;

update `wp_options` set option_value = concat('http://',@newDomain) WHERE option_name = 'siteurl';
update `wp_options` set option_value = concat('http://',@newDomain) WHERE option_name = 'home';

Edited by Andrew on 18/01/2013: Optimised SQL

Link here...

Ben Maden

Read more posts by Ben

4 comments on “Moving a WordPress database”

  1. This is a great little script. I had been using something similar, but this one is a bit more optimised.
    Cheers guys.

Leave a Reply

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

Shares