26 May, 2006
Find and replace text in mysql
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME,'find this string','replace it with this one');
Love what you've just read? Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
Hello! Welcome to Web development blog! My name is Ei Sabai and on this blog, I write about web development, mobile app development, latest web technologies and the likes. Read more 


Just what I needed thank you
Oh HELL YES. Greatly appreciated.
I was pushing a WordPress site from development server to production server, and all the functions that called the ‘guid’ meta data from the page array were pointing back at the dev server.
This beats updating per line.
UPDATE wp_posts SET guid = REPLACE(guid, ‘dev.server.com’, ‘prod.server.com’);
Like a charm. Thanks again!
Great little function – have expanded it a little to find and replace across a whole database – http://www.mjdigital.co.uk/blog/search-and-replace-text-in-whole-mysql-database/
Perfect for moving a WordPress blog from a development server to a live server and changing the domain name
I recently wanted to replace a string within MySQL on the fly, but the field could contain 2 items. So I wrapped a REPLACE() within a REPLACE(), such as:
REPLACE(REPLACE(field_name, “what we are looking for”, “replace first instance”), “something else we are looking for”, “replace second instance”)
This is the syntax I used to detect a boolean value:
REPLACE(REPLACE(field, 1, “Yes”), 0, “No”)
Hope this helps!