MySQL慢查询及explain

2020-03-24  本文已影响0人  xuanxiao

慢查询参数设置

1、long_query_time(单位秒,默认10)
MySQL的响应时间限制,超过此值,则记录进慢查询日志
2、min_examined_row_limit(默认值0)
MySQL查询时扫描的记录数
3、log_queries_not_using_indexes
默认情况下,慢查询不会记录查询时间不超过long_query_time但是不适用索引的语句,可设置此参数为on来记录没有使用索引的查询
4、log_slow_admin_statements
默认情况下,慢查询日志不会记录管理语句,可设置此参数为on来记录

慢查询日志参数

# Time: 2099-01-03T11:10:57.560412+08:00
# User@Host: root[root] @ localhost []  Id:   397
# Query_time: 2.000253  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 1
SET timestamp=1584933055;
select sleep(2);

Time:查询发生的时间
User@Host:客户端用户和IP
Query_time:查询所用的时间
Lock_time:等待锁的时间
Rows_sent:语句返回的行数
Rows_examined:语句执行期间从存储引擎读取的行数

通过show full processlist

当慢查询正在执行,但是此时数据库负载已经偏高了,慢查询日志中还没有此条查询信息,可以使用show full processlist来查看哪些线程正在运行

 Id     | User            | Host      | db   | Command | Time   | State                  | Info                  |
| 399 | root            | localhost | NULL | Query   |      9 | User sleep             | select sleep(10) 

Time:执行时间
Info:执行的语句

上一篇 下一篇

猜你喜欢

热点阅读