Reprint please retain the following author information Author: Jesse Blog: http://hi.baidu.com/leechl 3 o'clock just slept, more than 4, the colleague called to tell me that the user database was hung off. I get up and look at the list of processes. Mysql>show processlist;Out of several screens, no 1000 also have hundreds of, query statements to lock the table, hurriedly find the first locked thread_id, in the shell of MySQL execution. Mysql>kill thread_id;The process of killing the first lock table still does not improve. Since it doesn't improve, let's try to kill all the lock-list processes, the simple script is as follows. #!/bin/bash Mysql-u root-e "Show Processlist" | Grep-i "Locked" >> locked_log.txt
For line in ' Cat Locked_log.txt | awk ' {print '} ' Do echo "Kill $line;" >> Kill_thread_id.sql DoneNow Kill_thread_id.sql's content looks like this. Kill 66402982; Kill 66402983; Kill 66402986; Kill 66402991; .....Well, we execute it in the shell of MySQL and we can kill all the lock-list processes. Mysql>source Kill_thread_id.sql
Of course, it can be done in one line. For ID in ' Mysqladmin processlist | Grep-i Locked | awk ' {print '} ' Do Mysqladmin Kill ${id} Done |