27th August 2007

Find and Replace in a Wordpress Database

posted in Webmastering, Wordpress |

Recently Sebastian, a regular commenter on my Blog, moved his own blog from a blogspot.com domain to his own hosted and owned domain. Not wanting to have dozens (45 to be exact) comments linking to a domain that no longer exists I set out to update my blog.

Using the wordpress commenting interface was going to be quite painful to repeat the action 45 times, so I sought out a more scalable solution.

I went into my phpMyAdmin for the blog and found the table for comments, wp_comments. I checked out the form of the text string in that just to make sure I knew what syntax it was expecting, turns out its the full URL with the http:// included.

With that knowledge I was ready to set up my SQL query. We need to set-up the query in the form:

UPDATE the_table_name SET the_table_field = REPLACE(the_table_field,”string_to_find”,”string_to_replace”);

For this particular query the form looked like:

UPDATE wp_comments SET comment_author_url =
REPLACE(comment_author_url,"http://sebastianx.blogspot.com/","http://sebastians-pamphlets.com/");

I clicked “GO” and got this delightful response, “Affected rows: 45 (Query took 0.0061 sec)

Now on to find any other references in regular posts and pages.

You should link to him as well at http://sebastians-pamphlets.com/

If you liked this post please buy me a beer. Thanks.

Your IP Address is:
38.103.63.17

This entry was posted on Monday, August 27th, 2007 at 3:44 pm and is filed under Webmastering, Wordpress. You can follow any responses to this entry through the RSS 2.0 feed. All comments are subject to my NoFollow policy. You can skip to the end and leave a response. Pinging is currently not accepted.

There are currently 4 responses to “Find and Replace in a Wordpress Database”

Why not let me know what you think by adding your own comment! All the cool kids are doing it.

  1. 1 MyAvatars 0.2 On August 27th, 2007, Sebastian said:

    Thank You John!

    I appreciate that very much! :)

    Actually, I’m pretty close to leave the ugly blogspot thingy as is,
    plastered with links to my new blog, because redirecting all posts to
    the new main page could piss off visitors coming from blogs with a not
    that caring owner. That’s caused by the missing capability to redirect
    properly from blogspot to another blog. I’ll rather write off my former
    PageRank than annoying visitors.

    And that’s a warning addressing all free hosted bloggers. If you don’t
    own the domain, you don’t own your contents. Platforms like free hosts
    don’t allow server sided scripting usually, so one can’t 301-redirect.
    In the case of Blogger a technical flaw (the permalink variable is not
    yet populated in the HEAD section, hence it can’t be used to redirect to
    the actual posts’s new location with a zero meta refresh) hinders
    traffic management a blogger should be able to do. Sigh.

    John, I really like your new layout! Just AdSense is poorly targeted, it
    connects “Sebastian’s Pamphlets” correctly to “Specialists in
    anarchismn” but also to “Sebastian’s on the beach” and more crap like
    that. Actually, I’ve read Bakunin but I hate beaches ;) Also, why did
    you dump the Guinness logo in
    favor of a crappy Amstel image?

    Also, when submitting a comment I get an error message “Answer the
    question”, but there’s none. Did you forget to put the code required by
    the math-plugin in your theme’s comment script?

  2. 2 MyAvatars 0.2 On August 27th, 2007, John Honeck "JLH" said:
    I disabled the math plug-in it was causing conflicts and didn’t line up right in the template. Thanks for pointing that out.

    I can sit down and enjoy a Guiness or two, but if I’m going to really going to go at it then I’ll need something lighter. Amstel is just one lighter beer of choice at the moment…

  3. 3 MyAvatars 0.2 On August 27th, 2007, Sebastian said:

    Doh! Nothing can beat a guinness :)

    Thanks for posting my comment from my email, but it’s cluttered …

    I appreciate that very much! :)

    Actually, I’m pretty close to leave the ugly blogspot thingy as is, plastered with links to my new blog, because redirecting all posts to the new main page could piss off visitors coming from blogs with a not that caring owner. That’s caused by the missing capability to redirect properly from blogspot to another blog. I’ll rather write off my former PageRank than annoying visitors.

    And that’s a warning addressing all free hosted bloggers. If you don’t own the domain, you don’t own your contents. Platforms like free hosts don’t allow server sided scripting usually, so one can’t 301-redirect. In the case of Blogger a technical flaw (the permalink variable is not yet populated in the HEAD section, hence it can’t be used to redirect to the actual posts’s new location with a zero meta refresh) hinders traffic management a blogger should be able to do. Sigh.

    John, I really like your new layout! Just AdSense is poorly targeted, it connects “Sebastian’s Pamphlets” correctly to “Specialists in anarchismn” but also to “Sebastian’s on the beach” and more crap like that. Actually, I’ve read Bakunin but I hate beaches ;) Also, why did you dump the Guinness logo in favor of a crappy Amstel image?

  4. 4 MyAvatars 0.2 On August 28th, 2007, John Honeck "JLH" said:
    Sounds good.

Leave a Reply

  • Please Support

  • Marquette University

  • Sponsored