How to Find & Replace in MySQL

How to Find & Replace in MySQL featured image
(Last Updated On: December 13, 2017)

Sometimes, we need to find and replace certain strings or pieces of data in MySQL on the fly, for example if we’ve changed a Top Level domain (TLD) and want to update a bunch of links all in one go. For those times, the following command can be issued:

update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

This can be used, for example, to update strings contained in WordPress posts, such as a lot of links which you’d like to send to another domain. If you’d like specific code examples for doing this, please leave a public comment below, and I’ll update with this info.

1 thought on “How to Find & Replace in MySQL

  1. This is always a useful bit of code in case you need to update a lot of pages or posts in a WordPress (or other CMS) database all at the same time without having to go in and manually edit every single one!

Leave a Reply

Your email address will not be published. Required fields are marked *

Silicon Dales