Skip to content

Instantly share code, notes, and snippets.

@colinmollenhour
Created April 25, 2018 08:20
Show Gist options
  • Save colinmollenhour/38777d42da9003fdf25eca56b9fc5640 to your computer and use it in GitHub Desktop.
Save colinmollenhour/38777d42da9003fdf25eca56b9fc5640 to your computer and use it in GitHub Desktop.
Log Innodb Deadlocks
#!/bin/bash
dir=/root/deadlocks
[ -d $dir ] || mkdir -p $dir
cd $dir || { echo "Could not cd to $dir"; exit 1; }
mysql -be 'show engine innodb status;' \
| sed 's/\\n/\n/g' \
| awk '/TRANSACTIONS/{flag=0}flag;/LATEST DETECTED DEADLOCK/{flag=1}' \
> latest.txt
filename=$(head -n 2 latest.txt | tail -n 1)
if [ -f previous.txt ]; then
diff --brief latest.txt previous.txt > /dev/null
if [ $? -eq 1 ]; then
cp latest.txt "$filename.txt"
fi
else
cp latest.txt "$filename.txt"
fi
mv latest.txt previous.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment