当前位置:   article > 正文

mysql慢查询分析命令_【Mysql】分析Mysql慢查询之mysqldumpslow命令的使用

option '-h' requires an argument

mysql服务器有一项功能,可以检测到哪条sql语句查询得比较慢,就是慢查询slowlog,现在介绍如何开启。

在[mysqld]下面增加如下代码:

long_query_time = 1

log-slow-queries = /usr/local/mysql/data/slow.log

log-queries-not-using-indexes

long_query_time = 1 #定义超过1秒的查询计数到变量Slow_queries。

log-slow-queries = /usr/local/mysql/data/slow.log #定义慢查询日志路径。

log-queries-not-using-indexes #未使用索引的查询也被记录到慢查询日志中(可选)。

mysql自带了一个查看慢日志的工具mysqldumpslow。

执行mysqldumpslow –h可以查看帮助信息。

主要介绍两个参数-s和-t

-s 这个是排序参数,可选的有:

al: 平均锁定时间

ar: 平均返回记录数

at: 平均查询时间

c: 计数

l: 锁定时间

r: 返回记录

t: 查询时间

-t n 显示头n条记录。

实例:

mysqldumpslow -s c -t 20 host-slow.log

mysqldumpslow -s r -t 20 host-slow.log

上述命令可以看出访问次数最多的20个sql语句和返回记录集最多的20个sql。

mysqldumpslow -t 10 -s t -g “left join” host-slow.log

这个是按照时间返回前10条里面含有左连接的sql语句。

用了这个工具就可以查询出来那些sql语句是性能的瓶颈,进行优化,比如加索引,该应用的实现方式等。

附帮助:

[root@yzdb1 sqlpro]# mysqldumpslow -h

Option h requires an argument

ERROR: bad option

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 (al, at, ar, c, l, r, t), 'at' is default

al: average lock time

ar: average rows sent

at: average query time

c: count

l: lock time

r: rows sent

t: query time

-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 script)

-l don't subtract lock time from total time

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号