Mass string replace in MySQL

I have quite a few times needed to replace strings in my blog’s Db. One simple example is when I changed my blog address and all the URLs to the images were hardcoded. So, I had to go into the db and change the URLs from http://www.nalinmakar.com/blog to http://www.nalinmakar.com. Anyways, so a simple way of doing this is to goto the table that you want to use and open the SQL query interface. Run the following query:

UPDATE tableName SET columnName = REPLACE(columnName, oldString, newString)

so, in my case, I went into the wp_posts table and ran the following query:

UPDATE `wp_posts` SET post_content = REPLACE(post_content, “http://www.nalinmakar.com/blog”, “http://www.nalinmakar.com/”)

pretty neat… huh ??

Related Posts


About this entry