


























mysql有一个功能就是可以log下来运行的比较慢的sql语句,默认是没有这个log的,为了开启这个功能,要修改my.cnf或者在mysql启动的时候加入一些参数。
如果在my.cnf里面修改,需增加如下几行
long_query_time = 10
log-slow-queries = /usr/local/mysql/log/slow.log
long_query_time 是指执行超过多久的sql会被log下来,这里是10秒。
log
如果设置了参数log
-long-format,那么所有没有使用索引的查询也将被记录。在文件my.cnf或my.ini中加入下面这一行可以记录这些查询这是一个有用的日志。它对于性能的影响不大(假设所有查询都很快),并且强调了那些最需要注意的查询(丢失了索引或索引没有得到最佳应用)
# Time: 070927 8:08:52 如果日志内容很多,用眼睛一条一条去看会累死,mysql自带了分析的工具,使用方法如下:
命令行下,进入mysql
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-s,是order的顺序,说明写的不够详细,俺用下来,包括看了代码,主要有mysqldumpslow
-s c -t 20 host-slow.log上述命令可以看出访问次数最多的20个sql语句和返回记录集最多的20个sql。
mysqldumpslow
注意:my.cnf要写到
[mysqld]这一节下面。
原地址:http://blog.chinaunix.net/space.php?uid=618253&do=blog&cuid=1093402
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。