Use Percona Company's pt-query-digest analysis slow query log, analysis, statistical results are relatively clear
#!/bin/sh
Slowlog_path=/root/slow_query_log
Everyslow=/tmp/everydayslow
# #需要下载pt-query-digest
Pt_digest=/root/pt-query-digest
start_string=$ (grep ' date--date= "0 days ago" +%y%m%d ' ${slowlog_path}|head-1)
start_pos=$ (grep-n ' date--date= "0 days ago" +%y%m%d ' ${slowlog_path}|head-1|awk-f: ' {print $} ')
end_pos=$ (grep-n ' date--date= "0 days ago" +%y%m%d ' ${slowlog_path}|tail-1|awk-f: ' {print $} ')
print_linecnt=$ (Expr ${end_pos}-${start_pos})
# #start_string如果不为空, the analysis log
If [-Z "${start_string}"];
Then exit 1
Else
Grep-i "${start_string}"-A ${print_linecnt} ${slowlog_path} > ${everyslow}
/usr/bin/perl ${pt_digest} ${everyslow} >/tmp/anaslowlog_ ' Date +%y-%m-%d '
Fi
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Shell script parsing MySQL slow query log (slow log)