打开慢查询日志记录能够帮忙咱们优化mysql,通常建议开启,系统稳定后能够关闭
centos7 64位
mysql
版本 5.7.22
[root@localhost ~]# uname -a Linux localhost.localdomain 2.6.32-754.3.5.el6.x86_64 #1 SMP Tue Aug 14 20:46:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux [root@localhost ~]# mysql --version mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper
在[mysqld]
下加入如下mysql
slow_query_log=1 #启动慢日志 slow_query_log_file=/var/log/mysql/slow-mysql-query.log # 慢日志重启 long_query_time=1 # 慢日志定义时长1s,看我的产品需求
注意: slow_query_log_file对应目录须要设置成mysql用户权限,或者777,无需本身建立日志文件
# 查询配置 show variables like "%slow%"; # 查询慢查询时间 show variables like "long_query_time"; # 查询慢查询数量 show status like "%slow_queries%";