修改mysql配置文件,
默认是/etc/my.cnf,如果不是,那么find / -name my.cnf,找到对应文件 1、vim /etc/my.cnf
2、添加如下内容 #config slow log #启用慢查 slow_query_log=1 #慢查询输出日志文件位置,可以根据自己的需求设置 slow_query_log_file=/usr/local/webserver/mysql/data/mysql_slow_query.log #设置慢查询的时间为0.01秒 long_query_time=0.01 #慢查询日志输出形式为文件 log_output=file
3、修改my.cnf需要重启mysql服务器 service mysqld restart 或者 systemctl restart mysqld 或者 /etc/init.d/mysql.server restart
4、监控慢查询日志,及时捕获慢查询sql语句 [root@iZ2zeeefbpoojk9incccu6Z ~]# tailf /usr/local/webserver/mysql/data/mysql_slow_query.log 备注:出现在其中的语句,说明是执行时间超过long_query_time=0.01的语句
5、测试配置是否生效 在Linux环境的命令行mysql 命令登陆mysql后,执行select sleep(0.5); 或者windows环境使用navicat工具,在查询窗口里,执行select sleep(0.5);
本文由 MeiLe 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:2017-07-30 00:00:00