Update All MySQL URLs (WordPress FQDN Change)

You’ll find the following block of code on a myriad of websites. In my years of working with WordPress I’ve seen some really bizarre post URLs. Things like the server name and full server path to the user directory all in front of the actual FQDN.

For example: Serverbox21/home/users/johnsmith/public_html/

I’ve even seen companies host WordPress on a Windows Server! Those sites are a rats nest of URLs to fix because of all the custom tweaking that had to do to get the site working on a Windows environment.

#in phpmyadmin you can simulate the query before hitting 'go'. Also, when in doubt BACKUP! Always have a full MYSQL DB backup ready to go before running a query like this!!

UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'Existing URL','New URL');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Existing URL','New URL');
UPDATE wp_links SET link_url = replace(link_url, 'Existing URL','New URL');
UPDATE wp_comments SET comment_content = replace(comment_content , 'Existing URL','New URL');