Delete inactive and never-logged-in Drupal users

If you're interested in quickly deleting old and never used Drupal user accounts through mysql whether via ssh, phpMyAdmin, or other web interface use the following:

DELETE FROM users WHERE access < [unix date of oldest login to be kept]

DELETE FROM users WHERE access < 0

This should quickly delete the user accounts. I've used this in Drupal 4.7, 5, and 6.

When you use this code, be sure to recreate your UID 0 account otherwise you will have issues with anonymous user interaction. You can accomplish this with the following:
INSERT INTO users SET uid = 0, name = 'anonymous'; INSERT INTO users_roles VALUES(0,1); DELETE FROM cache;

User login

Navigation