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

Snippets has posted 5883 posts at DZone. View Full User Profile

Script To Search Locked Threads

10.22.2011
| 1712 views |
  • submit to reddit
        // 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