Who? Me?

Well you're here now, you might as well introduce yourself. Oh, me first? So I'm @irms and this is my blog. I care about things like entrepreneurship and how Pepsi tastes better out of a glass bottle. (read more)

Posts Tagged ‘search and replace’

PHP/MySQL Full Database Search and Replace

September 1st, 2009

I wrote this because I often need to move data-driven sites from development to production and addresses change.  (Wordpress sites, Wordpress MUDrupal,  and so on.)  This means I have to go through and change every occurrence of the url as it appears in the database.  So when the first few solutions for changing the site url aren’t doing the trick, I have to resort to the following MySQL snippet for updating every single table.

To find a string in a certain field and replace it with another string:

update [table_name]
  set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
Dangerous Code Ahead

Well, I got tired of doing that and wrote a handy snippet to find and replace across an entire database.

There are no checks or safeguards!  This is a quick and dirty script to be used at your own risk!

But if it’s useful, please feel free to say so in the comments.


UPDATE

Added two checkboxes:

  1. Set the script to never timeout (use with caution!)
  2. Do a case-insensitive find and replace. (use with caution!)

Download the updated .rar here

Post to Digg Post to Facebook Post to StumbleUpon

Tags: , , , , , , , ,
Posted in geek, technology | 11 Comments »

Posted by irms