Web Development Blog

by Ei Sabai Nyo

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.
Your name:   Your email:  

4 Responses to “Find and replace text in mysql”

  1. Andy says:

    Just what I needed thank you

  2. Benxamin says:

    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!

  3. MJ7 says:

    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

  4. 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!

Profile PicHello! 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 about me or have a look at some of the tips & resources I've written.
Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
We do NOT spam.
Your name:  
Your email:  

Tips & Resources

Tips & Resources
WordPress Web Hosting
Recommended web hosting providers for WordPress 3.0
iPhone Native App Development
Important steps into iPhone app development for beginners
iPhone Web App Development
Tips for iPhone web app development
Coupons for Web Developers
Get discounts on web hosting, domain names, templates, etc
10 Useful jQuery Snippets
Easy-to-use jQuery snippets for any website
HTML Email Newsletter
Step-by-step tutorial on how to code an HTML email newsletter
  • bluehost Hosting $6.95/month
  • Joomla Templates

Recommended Book

Categories