Saturday, June 19, 2010

Kill all mysql processes of a user

Sometimes you may need to see mysql processes of some definite mysql user.

For example you have several websites / scripts running on server, and want to see all mysql processes run by some website.

You can do it by running mysqladmin utility and removing text-like markup:

#mysqladmin -uUSERNAME -pPASSWORD proc | grep USERNAME| cut -f 2 -d ‘|’

If you want to kill all processes of a user, use this:

#mysqladmin -uUSERNAME -pPASSWORD proc | grep USERNAME| cut -f 2 -d ‘|’ | xargs -n 1 mysqladmin -uUSERNAME -pPASSWORD kill

Tested on a dedicated server running CentOS.

Good luck!

No comments: