How to Change the WordPress URLs in MySQL Database

Share this Article :

Before this I have experienced issues in wordpress migration of servers moving from the test server with an unregistered domain URL (www.ehowstuff.local) to the new virtual private server (VPS) with a registered domain (www.ehowstuff.com). After struggling to do research on google, I found the steps below that save a lot of time.

Step 1 : Update ‘siteurl’ and ‘home’ :

Select the WordPress database :

mysql> use wordpressdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

Check current value for ‘siteurl’ and ‘home’ :

mysql> SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');
+-------------+----------------------------+
| option_name | option_value               |
+-------------+----------------------------+
| home        | http://www.ehowstuff.local |
| siteurl     | http://www.ehowstuff.local |
+-------------+----------------------------+
2 rows in set (0.00 sec)

Update the value for ‘siteurl’ and ‘home’ :

mysql> UPDATE wp_options SET option_value = 'http://www.ehowstuff.com' WHERE option_name IN ('siteurl', 'home');
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

Check the updated value for ‘siteurl’ and ‘home’ :

mysql> SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');

+-------------+--------------------------+
| option_name | option_value             |
+-------------+--------------------------+
| home        | http://www.ehowstuff.com |
| siteurl     | http://www.ehowstuff.com |
+-------------+--------------------------+
2 rows in set (0.00 sec)

Optionally you can use below query to achieve step 1:

mysql> UPDATE wp_options SET option_value = replace(option_value, 'http://www.ehowstuff.local', 'http://www.ehowstuff.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Step 2 : Update the guid value in wp_posts table :

mysql> UPDATE wp_posts SET guid = replace(guid, 'http://www.ehowstuff.local','http://www.ehowstuff.com');

Step 3 : Update the post_content value in wp_posts table :

mysql> UPDATE wp_posts SET post_content = replace(post_content, 'http://www.ehowstuff.local', 'http://www.ehowstuff.com');

Step 4 : Update the meta_value value in wp_postmeta table :

mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.ehowstuff.local', 'http://www.ehowstuff.com');

wp-wall

Leave a Reply