慢查询日志分析脚本Mysql_slow_log_parser

慢查询日志分析脚本Mysql_slow_log_parser Mysql_slow_log_parser.txt 
txt脚本的名字要改名为pl

使用方式:

./Mysql_slow_log_parser.pl /data/mysqldata/3306/data/zsd-slow.log

之前zsd-slow.log的内容:

/usr/local/mysql55/bin/mysqld, Version: 5.5.25-log (Source distribution). started with:
Tcp port: 3306  Unix socket: /data/mysqldata/3306/mysql.sock
Time                 Id Command    Argument
# Time: 120702 12:10:27
# User@Host: root[root] @ localhost []
# Query_time: 1.558936  Lock_time: 0.000077 Rows_sent: 0  Rows_examined: 262144
use test;
SET timestamp=1341245427;
insert into t1 select * From t1;
# Time: 120702 12:10:31
# User@Host: root[root] @ localhost []
# Query_time: 3.077640  Lock_time: 0.000083 Rows_sent: 0  Rows_examined: 524288
SET timestamp=1341245431;
insert into t1 select * From t1;
# Time: 120702 12:10:38
# User@Host: root[root] @ localhost []
# Query_time: 6.081219  Lock_time: 0.000075 Rows_sent: 0  Rows_examined: 1048576
SET timestamp=1341245438;
insert into t1 select * From t1;
# Time: 120702 12:10:58
# User@Host: root[root] @ localhost []
# Query_time: 2.402953  Lock_time: 0.000152 Rows_sent: 1048576  Rows_examined: 2097152
SET timestamp=1341245458;
select * from t1 order by name;
# Time: 120702 12:13:18
# User@Host: root[root] @ localhost []
# Query_time: 13.259154  Lock_time: 0.000144 Rows_sent: 0  Rows_examined: 2097152
SET timestamp=1341245598;
insert into t1 select * From t1;
# Time: 120702 12:16:03
# User@Host: root[root] @ localhost []
# Query_time: 25.903786  Lock_time: 0.000089 Rows_sent: 0  Rows_examined: 4194304
SET timestamp=1341245763;
insert into t1 select * From t1;

之后输出的内容:

 Starting...
### 3 Queries
### Total time: 22.418013, Average time: 7.472671
### Taking 3.077640 , 6.081219 , 13.259154  seconds to complete
### Rows analyzed 524288, 1048576 and 2097152
SET timestamp=XXX;
insert into tXXX select * From tXXX;

SET timestamp=1341245598;
insert into t1 select * From t1;


### 1 Query
### Total time: 2.402953, Average time: 2.402953
### Taking 2.402953  seconds to complete
### Rows analyzed 2097152
SET timestamp=XXX;
select * from tXXX order by name;

SET timestamp=1341245458;
select * from t1 order by name;


### 1 Query
### Total time: 1.558936, Average time: 1.558936
### Taking 1.558936  seconds to complete
### Rows analyzed 262144
use test;
SET timestamp=XXX;
insert into tXXX select * From tXXX;

use test;
SET timestamp=1341245427;
insert into t1 select * From t1;


这个脚本可以很好的汇总和分析慢查询日志,晚上写个定时的脚本,输出发送邮件给自己,可以很好的查看,Mysql服务器慢查询的问题。
上一篇:连接RAC出现的问题--ORA-12514


下一篇:Dev GridView RowCellClick事件与MouseDown事件