Thursday, June 23, 2011

mysql replace text in field

Task: Assume that we have a table called articles. This table has a column/field called title. We have a lot of titles like "ubuntu administration tips xxx". One day we found that all these tips actually apply to all linxu systems, so we want to change all the titles from "ubuntu administration tips xxx" to "linux administration tips xxx"

Here is how we can do it quickly:

UPDATE articles SET title = REPLACE(title, 'ubuntu', 'linux');

No comments: