MySQL search and replace

How to perform a mySQL search and replace.

update tablename set field = replace(field,'search_for_this','replace_with_this');

If only I had found that earlier :-P

14 Comments

Wow, weird syntax.

You just saved my night :)

Thanks. Works great...

i've been searchin for this, thanks a lot ;)

And even after all this time, it's still helping people out. Saved me a ton of time. Thank you.

Thanks! This helped me a lot.

I put it in camel casing so that it was more obvious for myself, and hopefully for others who find this:

UPDATE tablename SET fieldname = REPLACE(fieldname, 'badterm','goodterm')

As another commenter said, it is odd syntax. But it works like a champ.

Thanks! This helped me a lot.

I put it in camel casing so that it was more obvious for myself, and hopefully for others who find this:

UPDATE tablename SET fieldname = REPLACE(fieldname, 'badterm','goodterm')

As another commenter said, it is odd syntax. But it works like a champ.

Eeek-a-rama!

Sounds so simple... but I never realised that function ever existed... now I have a new toy to play with!!!

Ta's a-lot-o...

(Phew... I was about to write/[copy] my own version)

Thanks a lot for the info! Very useful and time-saving!

Thanks a lot, I was just searching for this.

Thanks man - lifesaver ! ;-)

Wow, thanks so much!

I just wanted to clarify that the replacement works on the string and not the whole field.

Almost exactly 4 years later: THANK YOU!

Leave a comment

Recent Entries

  • WTF?

    Seen in a Safari crash report today: Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 com.apple.WebCore 0x00007fff849031b1 bool WTF::HashTable (*)(WebCore::SharedBuffer*)>, WTF::PairFirstExtractor (*)(WebCore::SharedBuffer*)> >, WebCore::CaseFoldingHash, WTF::PairHashTraits, WTF::HashTraits...

  • The Android Market is a terrible mess

    The Android Market is a terrible mess. Nearly every app I looked at had nothing but spam comments. Literally things like, “Follow me on twitter...

  • Bonne année

    Or Happy New Year as they say out there. :-)...

  • 5 Star Wars Status Updates

    The padawan not link to this cannot. Enjoy!...

  • Practical phishing prank, courtesy of McAfee

    McAfee SiteAdvisor is prone to pranks, thanks to the fact that it accepts anything from the URL. Let's play a game, SiteAdvisor is a phishing...