How to do a mass text search and replace with MySQL

I noticed that all my images on the posts here weren’t showing and it was because the url to their location was still pointing at the sub blog on The Comluv Network so I needed a way to edit the database to update the url to point to the files held here.

Easy with a REPLACE function on the wp_posts table.

You just need 3 things for the replace command :

  1. The row you’re altering
  2. The string you’re searching for
  3. The string you’re replacing with

UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "fiddyp.comluv.com/files/", "fiddyp.co.uk/wp-content/uploads/" )

It did the whole table of posts in less than a second. Sweet, now all my images are back to normal on this site.

About Andy

This is my personal website where I (occasionally) post about things going on in the world of me. I am the creator of CommentLuv and administrator of comluv.com
Code, PHP , , , , ,

4 responses to How to do a mass text search and replace with MySQL


  1. I’ll be bookmarking this, thanks!
    .-= witchypoo´s last blog ..Bust A Move =-.

  2. Very useful, its in my bookmarks now! By the way, nicely designed website.
    .-= Kalvster´s last blog ..Free Ubuntu VPN with HotSpot Shield (My Attempt) =-.

  3. Hey buddy, sorry this is so OT. My apologies for being gone so long but my current post describes it a bit.

    I’m ready now to re-subscribe and get back into your awesome blog! Slowly at first until I get full swing again. :)
    .-= Dennis Edell´s last blog ..What I’m Doing – What You Should Expect In The Very Near Future. :) =-.

  4. Did you remove subscribe to comments, or is it automatic now?
    .-= Dennis Edell´s last blog ..What I’m Doing – What You Should Expect In The Very Near Future. :) =-.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge