分类: Mysql/postgreSQL
2008-12-17 10:58:23
这是一个有用的日志。它对于性能的影响不大(假设所有查询都很快),并且强调了那些最需要注意的查询(丢失了索引或索引没有得到最佳应用)
# Time: 070927
8:08:52
# User@Host: root[root] @
[192.168.0.20]
# Query_time: 372
Lock_time: 136
Rows_sent: 152
Rows_examined: 263630
select id, name from manager where id in (66,10135);
这是慢查询日志中的一条,用了372
秒,锁了136
秒,返回152
行,一共查了263630
行
如果日志内容很多,用眼睛一条一条去看会累死,
mysql
自带了分析的工具,使用方法如下:
命令行下,进入
mysql/bin
目录,输入
mysqldumpslow –help
或
--help
可以看到这个工具的参数,主要有
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL slow query log. Options are
--verbose verbose
--debug debug
--help write this text to standard output
-v verbose
-d debug
-s ORDER what to sort by (t, at, l, al, r, ar etc), 'at' is default
-r reverse the sort order (largest last instead of first)
-t NUM just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup scrīpt)
-l don't subtract lock time from total time