Find and Replace in MySQL

I needed to do a find and replace on a couple of fields in a table and was stuck on the best way to this. Initially I was going to download a database dump and via a text editor find/replace and then re-upload but then I found out that MySQL has a Replace() function. All you need to do isUPDATE yourTable SET yourField = replace(yourField,from_str,to_str);The "from_str" performs a case-sensitive match when searching! Obviously you can also expand this to add any other logic like a WHERE clause etc.This probably works with other DB's ... I would of thought anyway
comments powered by Disqus