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

  • Moving on

    If everything goes well, next week I shall be the happy founder and owner of a shiny brand new company, under which I'll incorporate my...

  • Movable Type 4.2 is out

    Movable Type 4.2 is here with a lot of good news and new features. The new set of licences, if I get things correctly, is...

  • Using Movable Type as a CMS and NewsML feeds generator

    I'm putting the last touches on a CMS to generate custom NewsML feeds for internet portals. It's based on Movable Type 4.2 and allows for...

  • Google lets GMail certificate expire

    This expired certificate alert just showed up for my GMail account. Apparently Google let the SSL certificate expire for the smtp.gmail.com domain. In the...

  • Bon appétit

    We wanted to strip away all the nonsense. Do we really need a sommelier? Do we really need all the other accoutrements that you see...

Close