How to identify and remove Wordpress comment spam MySQL queries |

If you are using the default database configuration of Wordpress, then here’s a command line MYSQL query — also works in programs like PHPMyAdmin — to see what the breakdown is of approved, spam and waiting comments:
This will return a query that looks like what’s pictured and highlighted at the top of this post. These are the codes:
0 = pending comments
1 = approved comments
spam = comments you’ve marked as ’spam’ or deleted.
For some strange reason comments aren’t actually deleted in the Wordpress database when marked ‘delete’. I didn’t look in the code to see why this is being done this way, but to me when you delete something that means it actually gets deleted, not saved in the database in the spam bin. Perhaps there is a good reason why the Wordpress team is doing this but you don’t need to keep these deleted/spam comments unless you want to use them to detect spam patterns or abuse.
Assuming you don’t want to keep those comments, here is the code to clean out the spam comments from the wp_comments table in Wordpress:
Voila. You will now have a Wordpress-powered blog clean of spam/deleted comments. The busier your blog, the more these comments will start adding up so might want to set some sort of cron job that wipes out these comments once a week, month, whatever.
Did this post make you go hmm?
Maybe Related Posts (plugin generated)
- MySQL queries to sort by most comments by reader in WordPress blog
- Does adding CAPTCHA reduce the number of comments?
- [site news] Slow page loading issues
- [free code] How to import from Pivot 1.2x to Wordpress 1.5x
- How to access MySQL from Windows Command Prompt
- How to deal with (form) comment spammers





Hey thanks for this! By the way, what about wp_postmeta? My file is 11MB now…
Comment by davido — July 8, 2007 @ 7:37 am PST
0 = pending comments
1 = approved comments
Thanks
Comment by Leo — October 18, 2008 @ 12:21 pm PST
[…] A past Hmm post shows the query necessary to delete spam comments from a WordPress database. […]
Pingback by MySQL queries to sort by most comments by reader in WordPress blog » Make You Go Hmm — November 14, 2008 @ 10:12 am PST
I was so excited to find that even with little mysql knowledge I could go in and wipe out all comments on the database with a few clicks of the button instead of going through Wordpress admin panel. Access your PHPMyAdmin and select Structure to see the files in the database…. find wp_comments …. and then click the “empty” icon. Voilla .. they are all gone! Whoo hoo, all 5800 of them. Would have taken forever if I tried to do that through Wordpress admin panel deleting 20 at a time.
Thanks for this post, which lead me to PHPMyAdmin.
Comment by Lisa — August 6, 2009 @ 5:34 am PST