Wordpress - What SQL Query to do a simple find and replace
Best to do options, posts, post content and post meta:
UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');
Also see Searching Data using phpMyAdmin and MySQL | Packt Publishing. And Search RegEx is a good WP plugin to be able to search and replace with Grep through all posts and pages.
Update 6/16/2015: Using the tool linked in the next sentence is much better, as a simple find/replace as above in a database dump will break serialized data. See interconnectit.com WordPress Serialized PHP Search Replace Tool. This way, you don't break serialized data and won't need to run RegEx on post content, as the interconnect script changes URLs everywhere. I use that tool all the time to migrate sites to different domains, or to simply do a global change from http to https to force SSL without plugins and change all URLs in content to prevent insecure element errors.
The table where your URL is saved is wp_options. You should do an update on the columns that use the URL for your site:
UPDATE TABLE wp_options SET option_value = "new domain" WHERE option_name = "siteurl"
UPDATE TABLE wp_options SET option_value = "new domain" WHERE option_name = "home"
I might be missing some value, but whenever you do this find/replace process again, you can notice the values and tables that should be updated and add them to this script.
WordPress Codex has a nice guide on how to change a site URL, maybe that's even handier for you: Changing the Site URL
This is a great drop-in script that I use and it works beautifully with the serialized arrays that WP uses to store options. Just make sure to delete it from your remote server when you're done because it's a HUGE security risk.
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/