HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Linux command to kill all MySQL sessions from a specific User?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
killallusermysqllinuxspecificcommandfromsessions

Problem

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 !

Solution

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 :)

Code Snippets

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

Context

StackExchange Database Administrators Q#61531, answer score: 5

Revisions (0)

No revisions yet.