How can i kill all sessions from a user in mysql using a linux command line command?
I have a user that is using all on my database connections and insted of killing one by one i want to make a script to kill them all !

2 Answers 2


Try this :

mysql -uuser -ppassword -e 'show processlist' | grep USER_NAME | awk {'print "kill "$1";"'}| mysql -uuser -ppassword

The command will list the processes running in the database and return a kill 'query id'; command and pipe it into mysql again.
Be carefull with this command as there is no rollback form it :)

  • Thx for Up_One for me ! kk
    – Up_One
    Mar 22, 2014 at 18:11
  • When piping back to mysql, use --force, since a KILL command will fail if by change the connection has already terminated. Without --force this will abort all following KILL commands. Mar 22, 2014 at 20:20

You may also use common_schema's kilall() procedure from within your MySQL server. Use:

call killall('evil_user');

Disclosure, I am author of this tool.

  • very nice !!!!!
    – Up_One
    Mar 21, 2015 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.