WordPress runs off a MySQL Database. This is where all of your content is stored when you hit the save, publish or anything that needs to be remembered inside your WP dashboard. It’s this MySQL database that needs to be configures correctly in order to move your site onto a new domain. Otherwise you get the dreaded error message that many newbie web masters have probably lost a few hairs over.
Anyway, once you hook the database up correctly the battle still isn’t won… there’s still a list of things that you’ve got to change. This is because the old domain that your WordPress site was on previously has riddled the MySQL database with that old domain. You’ve now got to update it to the new domain in every place that it crops up…
But fear not, there are some sexy SQL hacks we all use to get the job done at lightening speed:
1. Change Siteurl & Homeurl
If you copy over your database and do not change both your Siteurl and Homeurl to the new domain, your site will NOT load. Use this SQL script to update both to your new domain.
[sql]UPDATE wp_options SET option_value = replace(option_value, ‘http://www.oldurl.com’, ‘http://www.newurl.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;[/sql]
2. Changing GUID (Globally Unique Identifier)
Changing the GUID is the big one. This little code will swap out every line of code containing the old domain and replace it with the new domain.
[sql]UPDATE wp_posts SET guid = REPLACE (guid, ‘http://www.oldurl.com’, ‘http://www.newurl.com’);[/sql]
3. Change The URL In Your Published Content
Any links in your posts from being on the old domain will need to be changed too. WordPress stores them in the database using an absolute path instead of a relative path so they all need to be updated manually… or with this code.
[sql]UPDATE wp_posts SET post_content = REPLACE (post_content, ‘http://www.oldurl.com’, ‘http://www.newurl.com’);[/sql]