Skip to content

Instantly share code, notes, and snippets.

@reinink
Created April 23, 2012 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinink/2471957 to your computer and use it in GitHub Desktop.
Save reinink/2471957 to your computer and use it in GitHub Desktop.
Search and replace within a MySQL database
UPDATE TableName set FieldName = replace(FieldName, 'find string', 'replace string')
@reinink
Copy link
Author

reinink commented Mar 15, 2013

For example, to update a website address in WordPress, do this:

UPDATE wp_posts SET post_content = replace(post_content, 'old-domain.com', 'new-domain.com');
UPDATE wp_posts SET guid = replace(guid, 'old-domain.com', 'new-domain.com');
UPDATE wp_options SET option_value = replace(option_value, 'old-domain.com', 'new-domain.com');

@reinink
Copy link
Author

reinink commented Apr 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment