Shell script parsing MySQL slow query log (slow log)

Source: Internet
Author: User
Tags mysql slow query log

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.