Suppose you have hundreds or thousands of spam comments on your wordpress blog, and you want to delete them all. You want to delete them in bulk, so you don’t have to click on them one by one or even page by page. Fortunately, there is a quick and easy way to do it from the command line. Here’s the outline:
- ssh to the machine that hosts the blog
- You need the name of the database user, the password for the database user, and the name of the database itself. You can get them by reading /etc/wordpress/config-$ServerName.php … then make a note of them in a safe place.
- mysql -ublogger -pSesameSwordfish123 blogger
- SELECT comment_approved,count(*) FROM wp_comments GROUP BY comment_approved;
+------------------+----------+ | comment_approved | count(*) | +------------------+----------+ | 0 | 1046 | | trash | 140 | +------------------+----------+ # where 0 indicates pending comments, # and 'trash' indicates comments that have already been moved to the trash
- DELETE FROM wp_comments WHERE comment_approved = ’0′;
Query OK, 1046 rows affected (0.06 sec)
- DELETE FROM wp_comments WHERE comment_approved = ‘trash’;
Query OK, 140 rows affected (0.01 sec)
