zoukankan      html  css  js  c++  java
  • mysql记录慢查询

    1. 首先找到my.cnf文件的位置,可以通过sudo find / -name my.cnf来查找, 如果是在OSX中通过homebrew安装,那么是找不到my.cnf这个文件的,可以在

      /usr/local/etc  目录下创建my.cnf文件,然后将需要重写的设置进行重写。设置好以后重新mysql服务即可

    2. 修改my.cnf文件
    [mysqld]
    slow-query-log=1   #开启记录慢查询
    log_output=TABLE   #将结果记录到数据库,如果无这条的话是默认记录到文件
    slow-query-log-file='long_query_log'  #记录慢查询的文件名
    long_query_time=0                     #记录走过该值的慢查询
    log_queries_not_using_indexes         #记录不用index的查询
    

          3.  修改完后重新启动mysql

          4.  进入mysql的控制台使用show global vairables;来查询变量设置状态

               如果遇到错误,使用 mysql_upgrade -u root -p --force 并重新启动 mysql 尝试解决

          5.  在数据库中进入表mysql.slow_log来查看记录状况

          6.  注意如果要使用mysql自带的工具来分析结果的话,一定要把数据存储到log文件中而不是数据库中

    sudo mysqldumpslow -a -s at -t 3 /usr/local/var/mysql/long_query_log 

     该命令的含义是:-a,不用-s或者-n来代替字符串与数字

                            -s,来指定排序方法,at为平均时间

                            -t,是来指定选择出排在最前边的三条

           7.  推荐使用第三方的工具来进行分析日志:

      • 可以使用brew install percona-toolkit来在MAC上安装percona来分析日志
      • 该工具官方网站为:https://www.percona.com/doc/percona-toolkit/2.2/pt-query-digest.html# 
      • 下载后使用pt-query-digest long_query_log即可对日志进行分析 

      报告分析:

    
    
    Column        Meaning
    ============  ==========================================================
    Rank          The query's rank within the entire set of queries analyzed
    Query ID      The query's fingerprint
    Response time The total response time, and percentage of overall total
    Calls         The number of times this query was executed
    R/Call        The mean response time per execution
    V/M           The Variance-to-mean ratio of response time
    Item          The distilled query

    Query Time: Total time including lock time query has taken
    Lock_Time: Total query query was in a locked state
    Rows sent: Total rows sent by server to client
    Rows examined: Total rows scanned by a MySQL server for a query
    QPS: Queries per seconds
    Concurrency :approximate concurrency for this query
     
     
  • 相关阅读:
    解读Unity中的CG编写Shader系列十 (光滑的镜面反射(冯氏着色))
    解读Unity中的CG编写Shader系列八(多光源漫反射)
    Unity3d《Shader篇》漫反射
    解读Unity中的CG编写Shader系列八(镜面反射)
    渲染物体到一张UITexture上
    解读Unity中的CG编写Shader系列六(漫反射)
    解读Unity中的CG编写Shader系列五(理论知识)
    解读Unity中的CG编写Shader系列四(unity中的圆角矩形shader)
    解读Unity中的CG编写Shader系列三
    解读Unity中的CG编写Shader系列二
  • 原文地址:https://www.cnblogs.com/wlemory/p/5504576.html
Copyright © 2011-2022 走看看