•  

How to Move a WordPress Website Using MYSQL and phpMyAdmin

Pin It

There are plenty of pros and cons to consider before choosing the right Content Management System (CMS) to use from project to project: WordPress, Drupal, MODx etc. One nice feature of using a system like Drupal and MODx is the use of relative paths in URL link location when storing parameters in the database. WordPress on the other hand uses absolute paths in URL linking.

NOTE:
“Absolute Paths: An absolute path is created whenever your link uses the full URL of an object or page. For instance, http://www.communitymx.com is an absolute path to a specific web site. This method is the best choice whenever you need to send a visitor to another site or need to get content from another site. While you can use it within your own site, there is rarely ever a need to do so.

Relative Paths: As you can probably guess, relative paths are used much more frequently than absolute paths. Any time you need to send a visitor to another page within your site or include an object from your site (like an image) on one of your pages a relative link will work just fine. Which form of relative link you should use will depend on how the site is constructed. Document and root relative paths each have a place in the building of a web site. Read on for a break down of each type.” -  Bryan Ashcraft

If you decide to change the URL of your WordPress website, for instance:  http://www.example.com/ to http://www.new-example.com/ there are some steps that you need to consider.

Also within your WP blog post content itself users may also use the old URLs when creating reference backlinks. All these values in the database will need to be changed when WordPress is moved. I’ll show you which database fields have reference or values related to the website’s content URLs that you want to modify.

The first thing to do is make a backup copy and move all files over. Once this has finished the first step is to tell WordPress the new URL location. We’ll be using SQL statements based on mySQL replace() function to directly modify the database, so you will need access to Here is the way to modify the value via MySQL database. You will need access to your phpMyAdmin or login to the DB server and run MySQL client as root. Use the following SQL command to update the new location of your WordPress website URL:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.example.com', 'http://www.new-example.com') WHERE option_name = 'home' OR option_name = 'siteurl';

After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guide field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:

UPDATE wp_posts SET guid = replace(guid, 'http://www.example.com', 'http://www.new-example.com');

If you have created reference backlinks within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all the internal links:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

There you go, take a look through your WP website to make sure everything is working the way it should.

Hope this helps!

Topher

Chris has a real passion for design and loves to share inspiration and tutorials with the design community. He's the curator here at designshifts.com, a freelance web consultant and developer and has a passion for the great outdoors.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

9 Comments

  1. Posted March 10, 2011 at 10:29 pm | Permalink

    OMG! I could have used this post two weeks ago to migrate a client’s blog from my dev. server to their live. I will definitely use these db replaces next time. Thanks!

  2. Ewen Cameron
    Posted April 11, 2011 at 6:47 pm | Permalink

    Hi this was very useful, but then I also read the statement below from the official WordPress Codex – Does the 2nd SQL Query you listed above change the guide settings as described below? If so it is stated that this should NEVER be changed, although being a newbie II could be getting mixed up.

    Important GUID Note

    When doing the above and changing the URLs directly in the database, you will come across instances of the URL being located in the “guid” column in the wp_posts tables.

    It is critical that you do NOT change the contents of this field.

    The term “GUID” stands for “Globally Unique Identifier”. It is a field that is intended to hold an identifier for the post which a) is unique across the whole of space and time and b) never, ever changes. The GUID field is primarily used to create the WordPress feeds.

    When a feed-reader is reading feeds, it uses the contents of the GUID field to know whether or not it has displayed a particular item before. It does this in one of various ways, but the most common method is simply to store a list of GUID’s that it has already displayed and “marked as read” or similar.

    Thus, changing the GUID will mean that many feedreaders will suddenly display your content in the user’s reader again as if it was new content, possibly annoying your users.

    In order for the GUID field to be “globally” unique, it is an accepted convention that the URL or some representation of the URL is used. Thus, if you own example.com, then you’re the only one using example.com and thus it’s unique to you and your site. This is why WordPress uses the permalink, or some form thereof, for the GUID.

    However, the second part of that is that the GUID must never change. Even if you shift domains around, the post is still the same post, even in a new location. Feed readers being shifted to your new feeds when you change URLs should still know that they’ve read some of your posts before, and thus the GUID must remain unchanged.

    Never, ever, change the contents of the GUID column, under any circumstances.

  3. Posted October 28, 2012 at 10:20 am | Permalink

    I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get set up? I’m assuming having
    a blog like yours would cost a pretty penny? I’m not very web savvy so I’m
    not 100% certain. Any recommendations or advice would be greatly appreciated. Appreciate it

    • Posted October 29, 2012 at 4:58 pm | Permalink

      It’ cost very little in terms of money, it costs you a lot of time, so if your going to start your own blog, you need to make sure you’ll have the time to take care of it!

      Hope it works out for you!
      Cheers.

  4. Posted November 10, 2012 at 12:25 am | Permalink

    I’ve moved WordPress numerous times doing the search and replace manually in the exported .sql file. So… Just because I’m lazy and would rather find out by asking rather than trial or error… Does this method lose the theme options? My method breaks the serialization of the theme options panel found in most themes, which isn’t that huge of a deal it just takes me about 10 minutes (if there are a lot of options) to go in and redo them.

    Thanks in advance,
    Dave

    • Posted November 10, 2012 at 12:41 am | Permalink

      Hi Dave,
      No, it shouldn’t break anything, all this is doing is replacing any leftover development domain alias ie http://www.dev.example.com and replacing them with http://www.example.com.

      Obviously first you should backup your data, but ya this is definitely one of the most effective technique. there are also a couple plugins that will do the work for you, root-relative-urls would work.

      Cheers.

      • Dave
        Posted November 10, 2012 at 12:59 am | Permalink

        Thanks a lot Chris, I’ll give your method a try next time!

      • Dave
        Posted November 28, 2012 at 8:48 am | Permalink

        Hi again Chris, I used this great free script to move a site online from my localhost today, very quick and easy. Give it a try sometime.

        http://interconnectit.com/124/search-and-replace-for-wordpress-databases/

        • Posted November 28, 2012 at 9:44 pm | Permalink

          Thanks Dave, Looks good for sure, just have to be really careful with it, and not forget about it in your root or someone could really mess with you! :)

          Cheers

3 Trackbacks

  1. By Migrating Wordpress to New Domain « Nathan Hein on January 11, 2013 at 9:24 pm

    [...] Topher wrote a great article over at designshifts.com about migrating a WordPress installation from one domain name to another domain name. Check out his article on How to Move a WordPress Website Using MySQL and PhpMyAdmin. [...]

  2. [...] b. Log into the PHPMYADMIN for the site.  Run a global search using % [old url] % and look for instances of the old URL to change. If you are running into trouble or if there are many to change, then this post may help. [...]

  3. By bastardising wordpress sites? on March 25, 2013 at 8:23 am

    [...] have the wrong path. There's possibly a new plugin to deal with this I haven't heard of otherwise this post tells you how to migrate to [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • WOOD Skateboard Rings