Home Notes Web development Find and replace text in MySQL

Find and replace text in MySQL E-mail
Thursday, 27 May 2010 00:10

Say you're moving a site from the development server to the production server, and the client has been making updates (adding content, etc.) while the site's been under development.  The problem is that they've been using absolute URLs (http://www.somesite.com/some/somepage.htm) instead of relative ones (some/somepage.htm), so you have to go in and change anywhere from several to several thousand links to either the new site's full URL, or make all the URLs relative.  What do you do?

You can do a simple find-and-replace in MySQL using the following statement:

UPDATE TABLE_NAME SET field_name = REPLACE(field_name, 'text being replaced', 'replacement text');