mysql 执行计划和慢日志记录

一、执行计划

1、作用
预估sql语句执行的时间,一般准确
2、格式: explain sql语句
3、type类型的快慢(all最慢,const最快)
all < index < range < index_merge < ref_or_null < ref < eq_ref < system/const

二、慢日志记录

1、基于内存
  a)、执行时间和log文件
  查看:show variables like '%query%';
  
  b)、查看未命中索引
  show variables like '%queries%';
  
  c)、修改
  set global long_query_time= 2;
  set global slow_query_log=ON
  set global slow_query_log_file=文件的绝对路径
  set global log_queries_not_using_indexes=ON
2、基于配置文件
  a)、启用配置文件
  mysqld --defaults-file 配置文件(可以自定义,也可用默认),建议备份
  b)、配置文件内容
  long_query_time= 2;
  slow_query_log=ON
  slow_query_log_file=文件的绝对路径
  log_queries_not_using_indexes=ON
  .....
 c)、重启服务
  net stop mysql
  net start mysql
原文地址:https://www.cnblogs.com/wt7018/p/11116577.html