Find and Replace in a Wordpress Database
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
On August 27th, 2007, Sebastian said:

