I’m fighting with a MySQL server at the moment. It’s freshly compiled from source and I’ve followed all of my tried and tested instructions but it won’t start up properly and leaves a load of process hanging around that need killing before I can try starting it again.
pkill wasn’t cutting it so I quickly put this together which kills all of the processes containing the term ‘mysql’ in them when doing a ps ax.
for FOO in `ps ax | grep mysql | grep -v grep | awk '{print $1}'`; do kill -9 $FOO; done








April 16th, 2007 at 1:54 pm
1) killall mysqld
2) killall -9 mysqld
3) ps auxw | grep [m]ysql | awk ‘{print $2}’ | xargs -r kill
4) ps auxw | grep [m]ysql | awk ‘{print $2}’ | xargs -r kill -9
#1 and #2 should work most of the time (just don’t use on Solaris)
#3 and #4 should catch more processes. The only difference being -9.
The grep [m]ysql stops grep matching it’s own process (alternatively do grep -v grep in the pipe-chain, as you have).
David.
April 16th, 2007 at 9:41 pm
Big up to xargs: (http://en.wikipedia.org/wiki/Xargs)
I’m surprised that’s the first I’ve heard of it. I also like the [] trick, it saves at least 4 characters.