Search and Replace in MySQL

I just went through a domain transfer for one of our websites, and the links in the posts are all pointing to OldSite.com rather than the NewSite.com. But it’s an easy fix, as long as you got Google.



I searched around and a very easy and quick way to search and replace text in a MySQL database is this query:
UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring");
You can also use WHERE clause to filter your query. An example would be:
UPDATE `mos2_content` SET introtext = replace(introtext,"<p>","") WHERE `title` REGEXP '-0';
This one removes all<p> tags from the posts. Hope this helps you guys looking how to search and replace text in mysql.

Source: Zimmertech

Related Posts with Thumbnails
Share and Enjoy:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • Netvibes
  • NewsVine
  • Ping.fm
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Buzz
  • BlinkList

Related posts:

  1. How To Repair Corrupted MySQL Tables in Linux I had this problem for days and can’t find a solution. What I had was .frm, .MYD and .MYI backup...
  2. 20+ WordPress Codes You Might Need On Your Next Project Undeniably, WordPress has been a premiere choice by web designers and internet publishers as their main blogging platform. One of...
  3. How to Upgrade PHP to 5.2 in CentOS Developing a Drupal community site has been really good for a while until I needed to search a module to...

Your email address goes here:

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>