MySQL/MariaDB search and replace

Software

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.

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!