MySQL/MariaDB search and replace

This is one of those things I'm constantly forgetting, especially since I use Postgres for most of my work.

To replace the occurance of a string in a field with another, use the following. This replaces the value of the field with the value of the field where a text substitution has taken place:

MariaDB [DB]> UPDATE table 
    -> SET field=REPLACE(field,'original','replacement');

The MariaDB site lists further details.


This is one of about 5000 posts on Rubénerd. View the home page for the latest, or related posts also tagged with:

If you liked this post, feel free to buy me a coffee, leave me a comment on Twitter, or email me at Thanks :).