MyBB Community Forums

Full Version: I want to delete all users and threads from my forum bu using SQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I came with a new site and within 15 days there are so many spammers and their spamming threads just messing my forum. I want to delete them all with one sql query running , can anyone help me with this ?
What are your criterias to delete them ? What do you want to do ? delete posts, delete users, both of them ?
yes both threads and users
Based on which criterias ? Or you want to delete all except some users id ?
i wanna delete all threads and users except admin usergroups
So, you can use the following query:
delete u, t, p
from mybb_users u
left join mybb_threads t on t.uid=u.uid
left join mybb_posts p on p.uid=u.uid
where u.usergroup=GID or concat(',', u.additionalgroups, ',') LIKE '%,GID,%'

Replace the two occurences of GID with the gid of your admin group.

If you have several admin usergroups, change the where:
where u.usergroup in (GID1, GID2, GID3) or concat(',', u.additionalgroups, ',') LIKE '%,GID1,%' or concat(',', u.additionalgroups, ',') LIKE '%,GID2,%' or concat(',', u.additionalgroups, ',') LIKE '%,GID3,%'

Note that the where using LIKE is if you use additional groups for your admins, if you set the admin group as primary you cen only use the part based on u.usergroup.

Second note: remember to do a Recount & rebuild after running the query.

important note : backup your database before running the query
it deleted my admin account except all the users

even i can't log in mu forum acp
Wow, I invert my condition, my bad.
You must negative the where and replace or with and:

where u.usergroup<>GID and concat(',', u.additionalgroups, ',') not like '%,GID,%'

Second way:
where u.usergroup not in (GID1, GID2, GID3) and concat(',', u.additionalgroups, ',') not like '%,GID1,%' and concat(',', u.additionalgroups, ',') not like '%,GID2,%' and concat(',', u.additionalgroups, ',') not like '%,GID3,%'

Luckily, you well read my important note and can restore your backup, then apply the good query.
i have backup of my forum , let me test again

worked it , Thank you so much for this , and please check my pm here or accept friend request on Discord