MySQL Search and Replace

I really, really wanted to do a search and replace in MySQL, but I just couldn’t find it. Then I did.

  update tablename set field = replace(field,'search','replace');

Using this simple bit of code means that I can rapidly search for any text and replace it within MySQL. I try not to use something like this too often, because it’s rather powerful – that means I can rapidly screw things up on a rather large scale (so I try to have good backups).

But there are times when nothing else will work, and the only way to get it done is to make use of something like this, and that’s when it’s good to have a utility of this sort in your toolbox. I’m glad that it’s there for just such an occasion.

Yippee! (via)


Posted

in