How to find and replace in MySQL

Sometimes you need to change some text in a MySQL table. For example, imagine you want to correct a spelling mistake or a reference in all your WordPress posts without having to change them one by one.

Here’s how to do it with a raw SQL command. This works only on a single table – repeat this for each table:

Note the use of standard ticks and back ticks here. First we’ll select the table in question (in this case wp_posts), then we’ll issue the find and replace query by selecting the column in the table (post_content), followed by the replace command.

As soon as MySQL comes back all references will have changed from “Old Text” to “New Text”.

Careful here: there is no undo function! Once executed, all changes are live instantly. Make a backup copy of your database before you do anything!

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!