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

Rent a flat in Paris

Going to the city of lights for a short stay? I rent a flat in Paris. Super comfortable and quiet, furnished, modern, stylish, with parking and a nice private garden... you'll love it (I did during the 8 years I lived there!). Please go to appartement-jardin-paris.com for details and booking.

About

This is the personal blog of François Nonnenmacher, founder and consultant at Ubiquitic, speaker, writer....

Recent Comments