• Home
  • About
Blue Orange Green Pink Purple

MySQL Search & Replace

Posted in MySQL. on Thursday, January 1st, 2009 by Mr. Matthews
Jan 01

It seems like every six months or so I need to do some site wide replacing (not often enough to commit this tip to memory it seems). If the site was built as flat HTML pages, I’ll use the find/replace feature in whatever editor I am using at the time. These days—more often than not—the actual site content is somewhere in a MySQL database. When that is the case, this one-liner comes in handy.

update table set field = replace(field,'find_this','replace_with_this');

As with any database change, you should first back up your database, or at the very least duplicate the table (with the content—of course).

Let’s say you wanted to change the words “Web site” to the more commonly used “website” in all of your site content. If the table holding the content is named tbl_content and the field was named page_content, then your MySQL command would look like this:

update table_content set page_content = replace(page_content,'Web site','website');

1 Comment

  1. Interwebtranet » Blog Archive » WordPress Search & Replace on January 2nd, 2009

    [...] a follow-up to the MySQL Search & Replace post, if you are using WordPress and need to make site wide changes there is a WordPress Search [...]



Leave a Reply

You must be logged in to post a comment.

Interwebtranet

  • Recent Posts
    • Don’t Let Snow Leopard Leave You Out In The Cold
    • Back To School 2009!
    • Mouse—Not The Clicking Kind!
    • Apple Safari 4 Beta
    • Dreamweaver CS3 Untitled Style Sheet Bug
  • Tags
    Bugs CSS Dreamweaver Freebies Google OS X Resources Safari
  • Categories
    • (X)HTML
    • Applications
    • CSS
    • Dreamweaver
    • General
    • MySQL
    • OS X
    • WordPress
  • Blogroll
    • Geeks & God
    • Westminster Academy
  • Archives
    • August 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
  • Search






  • Home
  • About

© Copyright Interwebtranet. All rights reserved.
Designed by FTL Wordpress Themes brought to you by Smashing Magazine

Back to Top