MySQL search and replace some text in a field MySQL search and replace some text in a field sql sql

MySQL search and replace some text in a field


Change table_name and field to match your table name and field in question:

UPDATE table_name SET field = REPLACE(field, 'foo', 'bar') WHERE INSTR(field, 'foo') > 0;


UPDATE table_name SET field = replace(field, 'string-to-find', 'string-that-will-replace-it');


 UPDATE table SET field = replace(field, text_needs_to_be_replaced, text_required);

Like for example, if I want to replace all occurrences of John by Mark I will use below,

UPDATE student SET student_name = replace(student_name, 'John', 'Mark');