Over a million developers have joined DZone.

Mysql Search + Replace

DZone's Guide to

Mysql Search + Replace

Free Resource
// Performing a search-and-replace through a table is easy with MySQL when you know how.
// http://blog.urbanmainframe.com/2008/07/mysql-search-replace/

update table_name set table_field = replace(table_field,'replace_that','with_this');

So, for example, let’s say you have a table called “posts” with a data stored in a field called “content” and you want to replace all instances of the word “dog” with “cat”, then your SQL would look like this:

update posts set content = replace(content,'dog','cat');

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}