当前位置:Gxlcms > 数据库问题 > mysql 5.6 设置慢查询

mysql 5.6 设置慢查询

时间:2021-07-01 10:21:17 帮助过:2人阅读

开启慢查询 1 或者 on long_query_time = 3 #记录超过的时间,单位是秒,默认是10s slow_query_log_file = /data/mysql/dev-service-node2-slow.log #指定日志文件存放位置,可以为空,系统会给一个缺省的文件host_name-slow.log log_queries_not_using_indexes = true #如果启用了慢查询日志,则此变量将控制那些不使用索引的查询是否应该被记录。如果进行记录,将使得日志文件迅速变得较大。 针对这个参数,在官方文档中还描述了一种比较特殊的情况: This option does not necessarily mean that no index is used. For example, a query that uses a full index scan uses an index but would be logged because the index would not limit the number of rows.

 

 

 

查询慢查询出现的次数;

show status like Slow_queries;

 

 

查看慢查询日志:

如果慢查询日志中的记录内容很多,可以使用mysqldumpslow工具,对慢查询日志进行分类汇总。
mysqldumpslow是mysql数据库自带的工具

执行:

mysqldumpslow -a -s t -t 7 /data/mysql/dev-service-node2-slow.log

 

这条命令会输出执行时间最长的7条sql语句。
这条命令中各个参数的意义:
-s, 是表示按照何种方式排序,c、t、l、r分别是按照语句query次数、query time、lock time、rows sent的总数来排序,
    at、al、ar则是以query time、lock time、rows sent的平均值来排序;
-t, 是top n的意思,即返回排序在最前面的多少条sql语句。

-g ,后边可以写一个正则匹配模式,大小写不敏感的;

 

 

#mysqldumpslow -a -s t -t 7 /data/mysql/dev-service-node2-slow.log

#输出参数解释:

 

Count: 15831  Time=8.46s (133943s)  Lock=0.00s (7s)  Rows=578.3 (9154400)

Count: 此语句执行了15831次

Time :  8.46s 是该语句执行的平均时间(有的说是执行的最长时间) 。(133943s) 是该语句执行时间的总和

Lock:   即是lock time  等待锁的时间

Rows: 即是rows sent , 578.3 表示发送给客户端的行总数  。 (9154400) 表示扫描的行总数

mysql 5.6 设置慢查询

标签:

人气教程排行