DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Script To Search Locked Threads
// The script will pick up the thread-id from innodb status page and select the last queries executed by that thread.
#!/bin/sh
mysql -e"show engine innodb status\G" | grep "MySQL thread id " | awk -F"," '{print $1}' | replace 'MySQL thread id' '' | tail | while read -r connectid
do
tail -1000000 /var/log/mysql/general.log | awk '$1 == "'$connectid'" || $3 == "'$connectid'" { print $0 }' | head
tail -1000000 /var/log/mysql/general.log | awk '$1 == "'$connectid'" || $3 == "'$connectid'" { print $0 }' | tail
done





