Mysql慢查询

开启慢查询

查看慢查询的状态

查看慢查询时间

查看慢查询文件路径

设置慢查询的两种方法

1)数据库SQL

set global slow_query_log=ON
set global long_query_time=1

重启Mysql配置会失效

2)修改my.cnf配置文件

[mysqld]
slow_query_log = on
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 1

设置完成后需要重启Mysql

service mysql restrat

分析慢查询日志

mysqldumpslow

常用选项

参数 说明
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default
-t just show the top n queries
-g PATTERN grep: only consider stmts that include this string
-r reverse the sort order (largest last instead of first)

-s的几个选项:
al: average lock time
ar: average rows sent
at: average query time
c: count
l: lock time
r: rows sent
t: query time

Example

posted @ 2020-08-09 22:18  kite97  阅读(130)  评论(0编辑  收藏  举报