WordPress Help

Remove WordPress comments from unregistered users

In a WordPress database, unregistered users are categorized with user_id = 0. You can remove their comments specifically by following these steps.

Warning: Always make a backup of your site before making any changes to the database.
  1. Sign in to phpMyAdmin.
  2. In phpMyAdmin, on the left menu, select the name of the database your site uses.
    select a database in phpMyAdmin
  3. On the top menu, select SQL.
    SQL tab in phpMyAdmin
  4. In the box below, enter the following code:
    DELETE wp_comments, wp_commentmeta FROM wp_comments INNER JOIN wp_commentmeta WHERE wp_comments.comment_id=wp_commentmeta.comment_ID AND wp_comments.user_id = 0; DELETE FROM wp_comments WHERE user_id = 0;
    Note: If your table prefix isn't wp_, you should replace all instances of wp_ in this code with your actual table prefix. You can check which prefix your site uses in the wp-config.php file.
  5. Select Go.

All comments from unregistered users are now removed from your site.

More info