zoukankan      html  css  js  c++  java
  • MySQL之慢查询日志分析

    在MySQL命令行中查看慢查询日志是否打开了:

    mysql> show variables like '%slow_query%';
    +---------------------------+-------------------------------------------+
    | Variable_name             | Value                                     |
    +---------------------------+-------------------------------------------+
    | slow_query_log            | OFF                                       |
    | slow_query_log_file       | /data/data_mysql/ip-172-31-22-29-slow.log |
    +---------------------------+-------------------------------------------+

    从上面可以看出没有打开慢查询日志的功能,现在我们打开一下,修改配置文件即可,修改后重启服务器。慢查询还有一个值比较重要,就是知道慢查询的时间:

    mysql> show variables like 'long_query_time';
    +-----------------+----------+
    | Variable_name   | Value    |
    +-----------------+----------+
    | long_query_time | 6.000000 |
    +-----------------+----------+
    1 row in set (0.00 sec)

    现在修改为两秒:

    mysql> set long_query_time=2;
    Query OK, 0 rows affected (0.00 sec)

    现在我们执行一个超过2秒的命令,看看效果:

    mysql> select * from sbtest1 group by k order by c desc  limit 1 ;
    +--------+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
    | id     | k      | c                                                                                                                       | pad                                                         |
    +--------+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
    | 453457 | 405843 | 99999937916-36259215105-74975791934-92968503070-23401591942-58585485414-51662851642-34478065889-45334022082-96106417569 | 77221010299-62957510796-01772448764-69834738016-84613386231 |
    +--------+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
    1 row in set (2.18 sec)

    现在我们查看一下慢查询日志;

  • 相关阅读:
    事务的特性(ACID)
    网络代理
    防止SpringMVC拦截器拦截js等静态资源文件
    Tomcat配置虚拟目录
    SpringMVC总结(SSM)
    Spring声明式事务总结
    Linux中MySQL忽略表中字段大小写
    MySQL之sql文件的导入导出
    MyBatis总结
    Linux网络
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/10284258.html
Copyright © 2011-2022 走看看