How to get slow log information by time in Mysql _mysql

Source: Internet
Author: User

Deal with a case today: database anomalies, the number of connections to the sudden increase.
Want to analyze the slow log, but a look at the slow log are several g, and is a short log format, to find that point in time relatively difficult. So write a script from the slow log time to extract the point log. Script:

Https://github.com/wubx/mysql-binlog-statistic/blob/master/bin/cutlogbytime

How to use:

Copy Code code as follows:
Cutlogbytime
#用于从慢日志用截取一个时间段的日志方便分析
./cutlogbytime/path/slowlogfile StartTime Endtime > Dstfile.log

Time to write timestamp

Mysql> Select Unix_timestamp (' 2013-04-05 ');
+------------------------------+
| unix_timestamp (' 2013-04-05 ') |
+------------------------------+
| 1365091200 |
+------------------------------+
1 row in Set (0.00 sec)

mysql> Select Unix_timestamp (' 2013-04-06 ');
+------------------------------+
| unix_timestamp (' 2013-04-06 ') |
+------------------------------+
| 1365177600 |
+------------------------------+
1 row in Set (0.00 sec)

./cutlogbytime/path/slowlogfile 1365091200 1365177600 > 20130405_slow.log

This way to get a day of log files on the smaller is also easy to analyze. And can be based on the day of the file, in a day to take a point in the log.

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.