Mysql Search + Replace
Join the DZone community and get the full member experience.Join For Free
// 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');
Opinions expressed by DZone contributors are their own.