How to change strings in MySQL tables

How to change strings in MySQL tables? e.g. I want to change domain.com to www.domain.com.

asked Jul 31, 2013 by EricaS. (210 points)

1 Answer

Use the REPLACE functions of MySQL: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

One example is like this:

UPDATE table
SET field = REPLACE(field, 'domain.com', 'www.domain.com')
WHERE field LIKE '%domain.com%'

The WHERE clause is not needed but can make execution faster.

answered Jul 31, 2013 by anonymous
edited Jul 31, 2013

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...