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

mensuelles Archives

Recent Entries

  • On Apple Safari's use of justified text in Reader

    On my professional blog, a take on Apple Safari's use of justified text in Reader....

  • Curated computing

    Perhaps the most pernicious proposition of the “everything must be open” crusade is the notion that curation is bad and anti-freedom. Soldiers of this crusade...

  • Death by Apple, the obsolescence of Flash

    Flash was created during the PC era – for PCs and mice. Flash is a successful business for Adobe, and we can understand why they...

  • Ogg (and Mozilla) objections

    Ogg objections by Måns: When challenged, three types of reaction are characteristic of the Ogg campaigners. On occasion, these people will assume an apologetic tone,...

  • Paris Web 2010 — Call for speakers

    (Disclaimer: I manage the communication for Paris Web, this is a copy of the official call for speakers.) Hello all, Paris Web is a French...