Posted by tonyv on August 18, 2008 at 3:29pm
I have an install with several thousand users. I have many that I would like to delete based on certain characteristics of their user name. For example, delete any user account with a username "*xyz"
Is there a problem with deleting users via sql query rather than using drupal admin to do this? It would be a great time savings to do it via query, but I don't know if just deleting from the user table is enough/would cause any problems.
Any ideas are greatly appreciated. Thanks!
TonyV

Comments
other modules?
I think that when you delete users from the admin menu, the user hook is called with an 'op' parameter of 'delete'...
http://api.drupal.org/api/function/hook_user
If other modules do anything in relation to users, they might want to perform some action each time a user is deleted. For example, a module might have inserted user-specific settings somewhere else in the database that would need to be deleted as well.
If there are no such modules installed, then I think that it would be fine. You can always backup your database first, then delete them. If anything goes bad, just restore everything back to normal.
I look forward to meeting with you this afternoon! Still on for 2:30?
-Mike Goodwin
Red Leaf Media
http://www.redleafmedia.com
I know this is an old thread, but
I have a situation where someone has hacked my site, and inserted him/herself as an authenticated user. When that rogue user is active, the anonymous user (uid = 0) is blocked, which created problems for people wishing to make a purchase through e commerce functionality (they could not put anything into the shopping cart, because uid = 0 was blocked). When I blocked Rogue User, Anonymous became unblocked. Hmmmm....
I am not sure what mechanism is at work here, but my solution is in progress. I would like to delete Rogue User, and suspect that the toggling relationship is code or script based, and not sourced through the database. But just to be sure that Rogue User has not connected something to a delete_user op, I wish to delete via phpMyadmin rather than through the Drupal hook.
Does this sound OK to all, and if so, which exact table do I target, and how would I identify the row? I have deleted all users (a small group of fellow site admins, so all that is left on the site is me as uid 1 and Rogue User.
Thanks in advance for any help.
REK
Deleting users in batch using SQL
in drupal 8 you must delete content for 3 tables. (users, users_data, and users_field_data)
-first make a copy of your database
-now go to your phpMyadmin console and pick your database
-Browse your user_field_data table in order to see the UIDS range you want to delete. usually low number UIDs are your real users..
- now delete the data for blocked users, in my case all users with UID > 240 are blocked
use this SQL commands -change UIDs number for your case.
DELETE FROM users_field_data WHERE uid >= 240
DELETE FROM users_data WHERE uid >= 240
DELETE FROM users WHERE uid >= 240