Yesterday I was helping my friend’s blog. She wanted to change her domain and move her hosting server for some reasons. She is using WordPress as her blog engine and of course using MySQL as the database server. To move a WordPress blog to another domain you need to change some configuration in the database. Especially if the data has absolute path URLs (e.g. http://www.willbechange.com/bla/bla/post.html).
After examining her database I found that many of the data in wp-options are using absolute path for the URL. And this data needs to be changed if you moved your domain. You can replace that data in the table with just one simple query in MySQL.
For example, the old domain is www.olddomain.com and the new domain is www.newdomain.com. In MySQL you can use the string function to replace strings called REPLACE(). This can be done with 1 simple query, here is the format:
UPDATE `table_name` set `field_name` = REPLACE(`field_name`, 'Keyword to be replaced', 'Replacement String');
For example, in my case I want to update wp-options, so here is the query:
UPDATE `wp-options` set `option_values` = REPLACE(`option_values`, 'www.olddomain.com', 'www.newdomain.com');
Run the query and all data in wp-options will be updated to the new domain.
It’s not hard, is it? Thanks for reading my blog. Please leave any comment if you have other ideas or tips to share or even a question.
