I have literally thousands of unpublished comments. I am wondering what is the easiest way to git rid of them altogether.
Thanks
For Drupal 6, run the following PHP code:
db_query('DELETE FROM {comments} WHERE status = 1');
For Drupal 7, run the following PHP code:
db_query('DELETE FROM {comment} WHERE status = 0');
You can also execute the query using Drush's sql-query command, for example
drush sql-query "DELETE FROM {comment} WHERE status = 0"
The better way I think is to use Views and Views Bulk Operations and you can do a simple admin interface to delete all of them.
Otherwise, you still can delete directly throw a SQL query.
For those using Drupal 7, using VBO has changed and the above comments about choosing Bulk Operations as the view style is not correct. Here are the steps to create a VBO page with Drupal 7 (I'll use the example of deleting all comments)
you can review this steps
Regards
For Drupal 7, this is really easy to achieve.
Content > Comments > Unapproved comments
.I would usually recommend to use VBO to delete comments or nodes in bulk but if you are in a situation when you have hundreds of thousands of comments and you don't have too much time, here is a sql query which will delete all unapproved comments along with all the revisions and data related to those comments which in my case was taking 1.2Gb of space in DB
DELETE c, rcb, dcb
FROM
comment AS c
JOIN field_revision_comment_body AS rcb ON (c.cid = rcb.entity_id)
JOIN field_data_comment_body AS dcb ON (rcb.entity_id = dcb.entity_id)
WHERE
c. STATUS = 0
Actually this worked for me:
drush sql-query "DELETE FROM comment WHERE status = 0"
i.e. no curly braces required.
However as explained elsewhere there are other tables in the db that reference comments so this approach is not advisable.
maybe there needs to be a module to do this properly, including field_data_comment_body, field_revision_comment_body etc Would be useful if you have a gazillion unpublished comments.
In the meantime this post here shows a better way:
DELETE FROM field_data_comment_body USING field_data_comment_body JOIN comment ON comment.cid=field_data_comment_body.entity_id AND comment.status=0;
DELETE FROM field_revision_comment_body USING field_revision_comment_body JOIN comment ON comment.cid=field_revision_comment_body.entity_id AND comment.status=0;
DELETE FROM comment WHERE status=0;