zoukankan      html  css  js  c++  java
  • mysql慢查询配置(5.7)

    刚装了Windows版mysql,想开启慢查询日志。

    修改D:mysql-5.7.23-winx64下my.ini配置文件,添加:

    [mysqld]
    slow_query_log = on
    slow_query_log_file = D:mysql_logsslow_query.log
    long_query_time = 2

    注:前面必须加[mysqld] 我这边配置前加了[mysql]导致读取报错。

    mysql: [ERROR] unknown variable 'slow_query_log=on'

    参数详解:
    slow_query_log = on #开启慢查询日志(或设置1)
    slow_query_log_file = filename #指定日志文件保存路径,不指定的话默认在数据库文件目录下,名为hostname-slow.log
    long_query_time = 2 #指定达到多少秒才算慢查询

    log_queries_not_using_indexes=on #记录没有使用索引的查询语句。!可能导致日志文件激增,谨慎使用。配合log_throttle_queries_not_using_indexes 使用。 

    log_throttle_queries_not_using_indexes #表示每分钟允许记录到slow log的且未使用索引的sql语句次数。配合long_queries_not_using_indexes开启使用。

    min_examined_row_limit = 1000 #查询检查返回少于该参数指定行的SQL不被记录到慢查询日志.需要开启log_queries_not_using_indexes=on 。注意:1查询结果数量是<不会被记录,=会被记录。2,这个参数开启后,long_query_time 参数失效 。
    log_slow_admin_statements #记录ALTER TABLE等语句引发的慢查询

    log_slow_slave_statements #记录从服务器产生的慢查询

    min_examined_row_limit=Num of Rows 类似于SELECT ... FROM TBL LIMIT N这样的全表扫描的查询,如果--log_queries_not_using_indexes被开启的话,因为用不到索引将要报告为慢查询,可以在配置文件中使用min_examined_row_limit=Num of Rows来设置,如果要检查的行数大于等于这个量的查询,才会被报告为慢查询。

    配置结束之后,需要重启才会生效。

    windows版:mysqld restart

    linux:service mysqld restart

    登陆数据库查询下环境
    show variables like '%query%';
    执行一个慢查询语句
    select sleep(3);
    查看文件,看日志是否生成。

    参考链接:https://blog.csdn.net/huoyuanshen/article/details/52699569

  • 相关阅读:
    加法的位运算实现
    C++装饰器模式
    字符串类型的相互转换
    手算CRC及其实现
    Linux下搭建C/C++编程环境
    Deepin Linux 实体机安装
    Atom + Texlive 配置 Latex 环境
    有关字符串的算法(KMP,Manacher,BM)陆续补充
    Linux 下大文件分割与合并
    Ubuntu /目录满,发现是docker image 太多解决办法
  • 原文地址:https://www.cnblogs.com/muxi0407/p/11606849.html
Copyright © 2011-2022 走看看