mysqlreplace

MySQL string replace


I have a column containing urls (id, url):

http://www.example.com/articles/updates/43
http://www.example.com/articles/updates/866
http://www.example.com/articles/updates/323
http://www.example.com/articles/updates/seo-url
http://www.example.com/articles/updates/4?something=test

I'd like to change the word "updates" to "news". Is it possible to do this with a script?


Solution

  • UPDATE your_table
    SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/news/')
    WHERE your_field LIKE '%articles/updates/%'
    

    Now rows that were like

    http://www.example.com/articles/updates/43

    will be

    http://www.example.com/articles/news/43

    http://www.electrictoolbox.com/mysql-find-replace-text/