In this article we’ll discuss an even more advanced method for cleaning up spam comments from your WordPress database using phpMyAdmin.
If you followed along with our 320: WordPress comment spam clean up article this would be one of the more advanced methods mentioned in that article.
The previous article 321: WordPress advanced comment spam clean up with search explained another advanced way of cleaning up spam from the database. The method discussed in this article can be used in conjunction with those steps in order to clean things up even better.
Multiple entry removal via advanced query
A lot of the time your spam comments are going to be mixed among good comments and hard to track down. You can use some advanced queries in phpMyAdmin to automate finding potential spam for removal using the steps below:
- First you’ll need to get to your WordPress database via the phpMyAdmin interface.
- Click on the SQL tab at the top.
- Enter in the following query, then press Go.
You’ll want to adjust this query specific to your WordPress database and table prefix.
In this example our database name is simply wordpress, and our table prefix is wp_.
SELECT comment_author, COUNT(comment_author)
FROM wordpress.wp_comments
GROUP BY comment_author
HAVING COUNT(comment_author) > 5
ORDER BY COUNT(comment_author)
DESCThe SQL query breaks-down as follows:
SELECT comment_author, COUNT(comment_author)
Selects the comment_author row and counts each entry.FROM wordpress.wp_comments
Sets the database and table we’re selecting from.GROUP BY comment_author
Groups our selection by the comment_author row.HAVING COUNT(comment_author) > 5
Only select entries that have 5 or more duplicate entries.ORDER BY COUNT(comment_author)
Order the results by the number of duplicate entries.DESC
Sort our entries descending, showing largest entries first.Â
- Copy (Ctrl-C) the text of the comment_author entry with the most duplicate entries.
- Click on the Search tab.
- In the first field Word(s) or value(s) to search for: paste (Ctrl-v) your copied text.
Place % symbols in-front and behind of the text for wildcards, now any entry containing the word at all will display.
Leave the Find: option as the default of at least one of the words.
In the Inside table(s): menu click on wp_comments to only search within that table.
Next to the Inside column: field enter in comment_author, then finally click Go.
- Click on Browse.
- Now you can review the comment_content row for that user to determine if it’s all spam content.
- In this case all comments were spam, so scroll to the bottom and click on Check All.
If not all of the comments were spam, you can simply place a checkmark beside the ones that you wish to remove.
- Then click on Delete at the bottom of the page.Â
- Confirm your deletions by clicking on Yes.
- MySQL should now return an empty result set if the deletion was successful.Â
Below you can see why this can be such an efficient method for finding spam in your WordPress database, using the different common WordPress comment rows we can find duplicate entries easily:
ÂÂ