replace part of a string in a mySQL table

Situation: you have a mySQL table with thousands or millions of records. You need to replace in most of the records a part of a string.
Classical example of such a situation is moving a WordPress website to another URL.


UPDATE `table-name` 
SET `field-name` = REPLACE(`field-name`,'part of the string you want to replace','corrected part of the string') 
WHERE `field-name` LIKE '%part of the string you want to replace%'

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image