MySQL string replace

khaled —  March 9, 2012 — 1 Comment

One of the MySQL functions that is extremely useful is the MySQL REPLACE() function. The REPLACE syntax looks as follows:


For example, if for some reason you need to update the links in your body fields and replace all your current links URL with new links URL you can use the following query:
update my_table set body=replace(body,’’,’’);




One response to MySQL string replace

  1. Cool, I didn’t know about this. For string replacements I am currently using the lib_mysqludf_preg UDF library which provides access to PCRE functions in MySQL:

    PCRE is great for complex string replacements that might not be possible with REPLACE. I could well imagine however that REPLACE should be more resource friendly and not take up as many CPU cycles, thus being the better first choice in that case.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.