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.