MySQL - Search and replace string

By xngo on June 18, 2019

MySQL provides REPLACE() function to search and replace string. Here is an example how to use it.

UPDATE tableName SET fieldname = REPLACE(fieldname, 'replace this string', 'with that string');
 
--Replace Smth with Smith from lastname value.
UPDATE Person SET lastname = REPLACE(lastname, 'Smth', 'Smith');

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.