WARNING – Always make a backup before modifying your database.
This came really handy when you have to manually migrate a WordPress website to another domain.
UPDATE wp_options SET option_value = replace(option_value, 'http://oldsite.url', 'http://newsite.url') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://oldsite.url','http://newsite.url'); UPDATE wp_posts SET post_content = replace(post_content, 'http://oldsite.url', 'http://newsite.url'); UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://oldsite.url', 'http://newsite.url');
Remember that in some cases table prefix is not the standard “wp”, but it may change (and actually it is good practice), so remember to check that before running it.