Published Tuesday 7th January 2014

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.

Photo of Ric


Ric is a senior web and game programmer with nearly 30 years industry experience and countless programming languages in his skillset. He's worked for and with a number of design and development agencies, and is the proprietor of QWeb Ltd. Ric is also a Linux server technician and an advocate of free, open-source technologies. He can be found on Mastodon where he often posts about the projects he's working on both for and outside of QWeb Ltd, or you can follow and support his indie game project on Kofi. Ric also maintains our Github page of useful scripts.

Blog posts are written by individuals and do not necessarily depict the opinions or beliefs of QWeb Ltd or its current employees. Any information provided here might be biased or subjective, and might become out of date.

Discuss this post

Nobody has commented yet.

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. 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.