• Euclides

    (@panafff)


    Hello guys, can someone help me with a spam issue? A friend′s site has been spammed, he uses buddypress and now the site about 20 K spam users. I would like to remove them all with a sql query, the website has mysql to handle the database. Do you have any command or script that help me do this quickly?

    Thank you in advanced!

Viewing 11 replies - 1 through 11 (of 11 total)
  • bernbe01

    (@bernbe01)

    hey there, if you just want a query you could use something like this:

    *substitute the user you want to keep for admin

    ****this will delete all users not matched on execution! please backup your database first!

    DELETE FROM wp_users WHERE user_login <> 'admin'

    or if you have a list of users to keep:

    DELETE FROM wp_users WHERE user_login NOT IN ('admin','second_user_to_keep','etc')

    let us know if you need anything else

    Thread Starter Euclides

    (@panafff)

    Hi mernbe01, thank you for the query, I will try it and let you know how it goes.

    Thread Starter Euclides

    (@panafff)

    Hey dude, it worked perfectly! Thank you very much again. Have a good week!

    bernbe01

    (@bernbe01)

    you too! thanks for letting us know and feel free to mark the thread as resolved if you have time

    take care

    catacaustic

    (@catacaustic)

    One thing to rememember is that you should also delete anything in the wp_usermeta table as well, as there will be a lot there if you’re trashing 20,000 users. ??

    That should be albe to be done by this (but take a backup of the table beforehand, just in case!!!):

    DELETE FROM wp_usermeta WHERE user_id NOT IN(1,2);

    The (1,2) are the ID’s of the users that you want to keep, comma separated.

    bernbe01

    (@bernbe01)

    darn i missed that! good catch and great point @catacaustic

    Thread Starter Euclides

    (@panafff)

    I just empty the table, thank you!

    Thread Starter Euclides

    (@panafff)

    Hey guys, my friends admin account is not working, actually the wp-admin link does not work now, it say:

    You do not have sufficient permissions to access this page.

    I tried to repair the database and tables but that din not work, any ideas?

    Thread Starter Euclides

    (@panafff)

    The problem seems to be after I ran the query to delete de wp_usermeta table

    catacaustic

    (@catacaustic)

    I just empty the table, thank you!

    NOOOOOOO !!!!!!!!!!!!!!!

    When you eptied the table, you removed all of your own admin accounts details, settings and permissions. That is why I had the NOT IN() clause in the SQL query… you do not want to delete anything from your own account.

    Now, you did take a backup of that table before you did emptied it, didn’t you???? If you did, re-install the values, and your account will be back and running. If you didn’t, you’ll have to talk to your hosting company to see if they have any backups that they can restore.

    bernbe01

    (@bernbe01)

    and if you dont want to use user id’s for your meta data delete, you can use a query like this, just know it is slower to use subselects

    make sure you edit the usernames in the subselect to the ones you want to keep

    DELETE FROM wp_usermeta WHERE user_id NOT IN(SELECT ID FROM wp_users WHERE user_login IN ('admin','second_user_to_keep','etc'))

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Query to delete Wp users’ is closed to new replies.