How Change and Update WordPress URLS in Database When Site is Moved to new Host?


Hello Everyone!

After migrating a WordPress site to a new URL either live or to a production or development server, the new URL strings in the mysql database need to be changed and updated in the various mysql database tables.

This method just uses the whole mysql database rather than a WordPress export/import from within, and is best suited for a straight swap. So you would copy all the WordPress files/folders to the new destination, set the correct ownership to those files = then do the database switcheroo.

Use the code as below and swap in your old and new URLs, no trailing slashes. Also if necessary change the table prefix values where applicable (ie wp_ )

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

 

Enjoy Code! | Enjoy Raghunath Blog

Advertisements

Sr. Software Engineer

Tagged with: , ,
Posted in Wordpress
4 comments on “How Change and Update WordPress URLS in Database When Site is Moved to new Host?
  1. Good day! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any suggestions?

  2. I am regular reader, how are you everybody?
    This post posted at this site is actually good.

  3. Joan says:

    Great article.

  4. Danuta says:

    Blogging to make money involves a lot of
    givecontentand takepurchasesbut it will always be mostly giving on your part.
    Instead of just talking about the ho-hums
    of daily life as a leader, create an encouraging corporate
    environment for all who may be reading the blog.

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

%d bloggers like this: