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.