DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Mysql Search + Replace

09.09.2008
| 3939 views |
  • submit to reddit
        // Performing a search-and-replace through a table is easy with MySQL when you know how.
// http://blog.urbanmainframe.com/2008/07/mysql-search-replace/

update table_name set table_field = replace(table_field,'replace_that','with_this');

So, for example, let’s say you have a table called “posts” with a data stored in a field called “content” and you want to replace all instances of the word “dog” with “cat”, then your SQL would look like this:

update posts set content = replace(content,'dog','cat');