Utterly Boring dot com

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.

Posted by Jake on 12/21/05 @ 03:01 PM
Posted in Geekdom | 6 Comments | Permalink
Submit to digg, del.icio.us, reddit, or stumbleupon

6 Comments

Patrick said on 12/22/05 @ 08:33 AM:
Hmm... interesting. Which db are you cleaning out?

Jake said on 12/22/05 @ 08:46 AM:
I was using that to make some descriptions consistent in Sunray's online database.

Diederick said on 12/23/05 @ 10:49 AM:
Thank you very very very very very much.

Paul said on 12/23/05 @ 06:36 PM:
I didn't know that. Does it only work for MySQL?

Jake said on 12/24/05 @ 12:11 AM:
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 said on 12/28/05 @ 01:38 AM:
I don't think it's standard SQL

Post a comment












HTML Allowed: a href, b, br, p, strong, em, ul, li, blockquote




Note: There is currently a problem with special characters causing errors when you try to comment, so if you're copying information from another Web site that has smart quotes or em dashes or ellipses or similar, please remove them and manually type them out.

Comment Policy: Comments on older entries or comments containing a bunch of links are moderated automatically on this site to help fight comment spam. If you don't see your comment after submitting, it will appear on the site after it has been approved. We also reserve the right to remove your comment for any reason we see fit, but if you keep it remotely on topic, it'll stay.

What are you doing down here? Don't you have something better to do? Like Go Back To The Top of the page, or even see who created this site? This site is © 2001 - 2008 by the Utterly Boring folks at UtterlyBoring.com. Steal my content, as I probably did, too, just link to my site or the original site. Batteries not included. One size fits all. Not for off-road use. Not for internal use. Do not taunt Happy Fun Ball. Technorati Profile.