Posted: 7th January 2014

Author: Ric

Tagged: Tutorials

Global find and replace in MySQL

I often find myself looking for this quick snippet of SQL code, even though I use it pretty much weekly. So, partly for my own reference, here's a quick line of SQL to find and replace any string of text in a single field throughout an entire database table.

UPDATE tblName SET fldName = REPLACE(fldName,'text to look for','replacement text');

Swap out the tblName reference for your table name, the fldName references for the field you want to make the replacement in, and the text to look for and replacement text values for your find and replace strings. REPLACE() is a case-sensitive MySQL function.

Blog posts written by former QWeb employees are not necessarily an accurate indication of the current opinions of QWeb Ltd and the information provided in tutorials might be biased or subjective, or might become out of date.

Discuss this post

Leave a comment

Your email address is used to notify you of new comments to this thread, and also to pull your Gravatar image. Your name, email address, and message are stored as encrypted text and you won't be added to any mailing list and your details won't be shared with any third party.

This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.