Mass Replace String in MySQL Database
Filed in: Web Development, WordPress — April 24th, 2005Since I have changed the blog script path from my previous installation. I need to update the files and images path URL in all previous posts.
Do it manually? No way. There are hundreds of them!
There are basically two ways suggested in my search. First, output the database table and use text editor’s “search and replace” function. Second, use MySQL REPLACE function.
Of course, the later is better and easier solution. Here is the SQL query to replace string in database table:
[sql]UPDATE table_name SET column_name = REPLACE(column_name,”original_string”,”replace_string”)[/sql]
Here is what I did to change the path URLs in all the previous posts.
[sql]UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`,”liewcf.com/wp”,”liewcf.com/blog”)[/sql]
300+ records updated. Time spend: 1 minute. ![]()


