MySQL Replace

I have decided to post this little snippet as I have been searching how to replace certain text within certain fields for quite a while. The basic syntax is very simple.

The aim here is to replace some text with different text in multiple rows of your database's table. This is a handy function if for example you want to change URLs. The basic syntax is as follows:


UPDATE `table_name` SET `table_field` = 
REPLACE(`table_field`,"replace_what","replace_with");


To replace http://227net.com to http://www.skiffie.com see the following example:


UPDATE `table_name` SET `table_field` = 
REPLACE(`table_field`,"http://227net.com","http://www.skiffie.com");

Syndicate content