vi mysql_lock_check.sh
#阻塞的源头信息。
echo ""
echo ""
echo "阻塞的源头事务信息输出........"
mysql -uroot -prootroot -t -e "
select lc.requesting_trx_id , lc.requested_lock_id , lc.blocking_trx_id , lc.blocking_lock_id
from information_schema.innodb_lock_waits lc where lc.blocking_trx_id in(
select trx_id from information_schema.innodb_trx where trx_state='RUNNING');" > LOCK3.txt
cat LOCK3.txt |grep -v "+" > LOCK4.txt
sed -i '1d' LOCK4.txt
while read rows
do
result=$(cat LOCK2.txt |grep "RUNNING")
if [[ "$result" != "" ]]
then
kill_id=`echo $rows |cut -d "|" -f 4`
echo "事务: "`echo $rows |cut -d "|" -f 4` " 正在阻塞事务:"`echo $rows |cut -d "|" -f 2`
echo "如果你想杀掉引起阻塞的源头,你可以执行: kill "`cat LOCK2.txt|grep $kill_id |cut -d "|" -f 10`"; 但是你必须确认这样做是安全的。"
echo ""
fi
done < LOCK4.txt