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. ![]()
Like this post? Please share:
Follow @liewcf on Twitter; Join Facebook page; Subscribe to free newsletter for updates like this article..





Pingback: Mr.Brown’s Blog » A good site for WP Tricks
Pingback: SocInf » Archivio Blog » mySQL. Sostituzione automatica di stringhe.
Pingback: NalinMakar.com : Blog Archive : Installed UTW3 for Tags
Pingback: mySQL. Sostituzione di massa di stringhe » Studio404
Pingback: How to Update Text Link Ads Affiliate TinyURL in One Shot
Pingback: Allan at Work » Blog Archive » Change of Name