Managing comments on your WordPress site via PhpMyAdmin or SQL

Manage WordPress comments via MySQL commands.

This is something interesting and time saving method. Yeah, it’s a bulk, one click option to remove unwanted comments from your WordPress websites. If you are using multiple WordPress websites, this should help you to save many hours.

If your WordPress sites are not properly configured against Spam comments, you may receive 100s of comments per day or week.

You can use any of the Anti Spam plugins available on internet, against this type of Spam comments attack on your website. You can remove those comments from the WordPress dashboard

Access WordPress dashboard → Click on “Comments” from the left side tab → You can sort and select comments from there → Select bulk action.

This image will help you on how to do so:

remove-wordpress-comment

But you can only select a maximum of 20 comments from there. That’s the only problem. If you have to remove 1000s of emails this method will be a painful one. Here we are going with a smart solution for this problem. Yeah you can do this from the PhpMyAdmin tab via cPanel/WHM or from the MySQL interface via command line.

How to remove unwanted comments from from your WordPress site?

The comments are categorized as Pending, Approved, Spam and Trash. Here you can select anyone of this to execute the MySQL query.

Step 1 : Log into cPanel and access PhpMyAdmin.

Step 2 : Select the database correctly.

Step 3 : Click on SQL tab; then execute your query.

remove-wordpress-comment-1

Managing approved comments

You can select all approved comments by executing the following command:

use database_name;
select * from wp_comments WHERE comment_approved='1';

To remove all approved comments from your WordPress’s database, use the following query:

use database_name;
delete * from wp_comments WHERE comment_approved='1';

Select and remove all unapproved comments

Here replace 1 in the above command to 0, that’s it.

You can select all unapproved comments by executing the following command:

use database_name;
select * from wp_comments WHERE comment_approved='0';

To remove all unapproved comments from your WordPress’s database, use the following query:

use database_name;
delete * from wp_comments WHERE comment_approved='0';

Managing Spam and Trash comments

remove-wordpress-comment-2

You can select all Spam comments by executing the following command:

use database_name;
select * from wp_comments WHERE comment_approved='spam';

To remove all Spam comments from your WordPress’s database, use the following query:

use database_name;
delete * from wp_comments WHERE comment_approved='spam';

You can select all Trashed comments by executing the following command:

use database_name;
select * from wp_comments WHERE comment_approved='trash';

To remove all Spam comments from your WordPress’s database, use the following query:

use database_name;
delete * from wp_comments WHERE comment_approved='trash';

That’s it buddy!!
Let me know if you have any questions.

  1. Accessing PhpMyAdmin without cPanel login?
  2. All details about a cPanel user in a single command
, , , ,

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

4 thoughts on “Managing comments on your WordPress site via PhpMyAdmin or SQL

  1. Hi Arunlal. Nice article. But there is an error I would like to point out.
    To delete unapproved comments it should be:
    delete * from wp_comments WHERE comment_approved=’0′;

    You have by mistake written:
    comment_approved=’1′;

    Once means the comments that have been approved.
    I hope it helps 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *