Search And Replace in MySQL

This is just mostly for my reference so I don’t have to keep digging in the Google cache to get this site:

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

I’ve probably used this bit of SQL a dozen times in the last week while doing some pruning/cleanup in a work database, I just kept forgetting the exact syntax.

Comments

Patrick says:

Hmm… interesting. Which db are you cleaning out?

Jake says:

I was using that to make some descriptions consistent in Sunray’s online database.

Diederick says:

Thank you very very very very very much.

Paul says:

I didn’t know that. Does it only work for MySQL?

Jake says:

Honestly, I have no idea, Paul. I don’t use anything but MySQL (though I have Postgres installed on this server for another site, but I’m not about to setup a database just to test it).

Diederick says:

I don’t think it’s standard SQL