MySQL obtains slow log information by time.

Source: Internet
Author: User

MySQL obtains slow log information by time.

Handle a case today: the database is abnormal and the number of connections suddenly increases.
I want to analyze the slow log, but I can see that the slow log is several GB, and it is a short log format. It is relatively difficult to find the time point. So I wrote a script to extract point logs from slow logs by time. Script:

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

Usage:
Copy codeThe Code is as follows: cutlogbytime
# It is used to capture logs for a period of time from slow logs for convenient analysis
./Cutlogbytime/path/slowlogfile starttime endtime> dstfile. log
Timestamp to be written

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

In this way, it is easier to analyze the log files of one day. In addition, logs generated at a certain time point of the day can be retrieved Based on the files of the day.

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.