Update WordPress Site URL

When you move a WordPress installation (e.g. from production to your local development environment), you’ll need to update the wp_options table to reflect the new URL.

The following script (tested on MySQL) lets you find and replace all URLs that match the old url with a new one using a correlated update statement:

Just replace “http://www.oldurl.com” and “http://www.newurl.com” with your old and new URLs respectively.

update wp_options a inner join ( select option_id, replace(option_value, 'http://www.oldurl.com', 'http://www.newurl.com') as option_value from wp_options where option_value like 'http://www.oldurl.com%' ) b on a.option_id = b.option_id set a.option_value = b.option_value