zoukankan      html  css  js  c++  java
  • 解读MySQL的慢日志

    完整的慢日志格式一般如下:

    1 # Time: 130320  7:30:26
    2 # User@Host: db_user[db_database] @ localhost []
    3 # Query_time: 4.545309  Lock_time: 0.000069 Rows_sent: 219  Rows_examined: 254
    4 SET timestamp=1363779026;
    5 SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';

    第1行,代表记录慢日志的时间,格式是YYMMDD H:M:S.  注: 这是MySQL服务器的时间,可能和你的当地时间不同

    第2行,很明显不多解释

    第3行,是整个语句的query time, Lock time, 返回或者发送了多少行, 执行的行数

    第4行,是语句真正发生的时间

    第5行,具体语句

    很多人都知道MySQL的slow log里面记录了几种:

    long_query_time     :  设定慢查询的阀值,超出次设定值的SQL即被记录到慢查询日志,缺省值为10s  
    slow_query_log      :  指定是否开启慢查询日志  
    log_slow_queries    :  指定是否开启慢查询日志(该参数要被slow_query_log取代,做兼容性保留)  
    slow_query_log_file :  指定慢日志文件存放位置,可以为空,系统会给一个缺省的文件host_name-slow.log  
    min_examined_row_limit:查询语句的执行行数检查返回少于该参数指定行的SQL不被记录到慢查询日志  
    log_queries_not_using_indexes: 不使用索引的慢查询日志是否记录到索引
    

    除了min_examined_row_limit参数外,其他几个参数都比较常见的,这个是我第一次见到,记录下来,这个参数可以用来排除在检查慢查询时,一些不必要的干扰

    Command-Line Format --min-examined-row-limit=#
    System Variable Name min_examined_row_limit
    Variable Scope Global, Session
    Dynamic Variable Yes
    Permitted Values (32-bit platforms) Type integer
    Default 0
    Min Value 0
    Max Value 4294967295
    Permitted Values (64-bit platforms) Type integer
    Default 0
    Min Value 0
    Max Value 18446744073709551615

    这个参数是用来设置慢查询的最小examined扫描行数。

    参考资料:

    https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_min_examined_row_limit 

    https://www.digitalocean.com/community/tutorials/how-to-use-mysql-query-profiling 

    http://calladeveloper.blogspot.com/2013/03/howto-read-mysql-slow-query-log.html 

  • 相关阅读:
    maven
    git 流程
    配置错误:不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的(
    ui选型
    重构
    http网站上传文件大小问题【没测试过】
    分页sql写法【只用最新的】
    dom响应事件
    html多个水平并列组件自适应等高的做法
    js写法【3】
  • 原文地址:https://www.cnblogs.com/sunss/p/6548588.html
Copyright © 2011-2022 走看看