Differences
This shows you the differences between two versions of the page.
mysql:scripts [2008/11/21 18:01] a |
mysql:scripts [2009/05/25 00:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Kill every MySQL SELECT older than X seconds ===== | ||
- | <code bash|f kill.sh> | ||
- | #!/bin/bash | ||
- | SEC=$1 | ||
- | IFS=’|’ | ||
- | if [[ $SEC -lt 1 ]]; then | ||
- | echo “Usage: $0 SECONDS” | ||
- | exit 1 | ||
- | fi | ||
- | mysqladmin proc -v|grep Query|grep -Evi “delete|update|insert|alter table” |while read dummy qid qusr qhost qdb qstat qsec qstat2 query | ||
- | do | ||
- | if [ $qsec -gt $SEC ]; then | ||
- | echo “Killing query $qid…” | ||
- | mysqladmin kill $qid | ||
- | fi | ||
- | done | ||
- | </ | ||
- | |||
- | ===== Sniff the MySQL traffic on the fly ===== | ||
- | <code cli> | ||
- | # tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e ' | ||
- | while(<> | ||
- | if(/ | ||
- | if (defined $q) { print " | ||
- | $q=$_; | ||
- | } else { | ||
- | $_ =~ s/^[ \t]+//; $q.=" $_"; | ||
- | } | ||
- | }' | ||
- | </ | ||
- | |||
- | |||