zoukankan      html  css  js  c++  java
  • mysql开启关闭慢查询日志

    在日常开发中,为了监控数据库的执行情况,往往我们需要开启慢查询日志。通过检查慢查询日志来确定sql的方向。但是长时间的运行势必导致慢查询日志过大,这种情况就需要将旧的慢查询日志保存起来,然后重新生成一份慢查询日志。
    ————参考博客:正确安全清空在线慢查询日志slow log的流程

    查看当前慢查询的信息

    mysql> show variables like '%slow%';
    +---------------------+------------------------------------------+
    | Variable_name       | Value                                    |
    +---------------------+------------------------------------------+
    | log_slow_queries    | ON                                       |
    | slow_launch_time    | 2                                        |
    | slow_query_log      | ON                                       |
    | slow_query_log_file | /mysqllog/slow_log/slow_queries_3306.log |
    +---------------------+------------------------------------------+
    4 rows in set (0.00 sec)
    

    停止当前慢查询日志

    mysql> set global slow_query_log=0;
    Query OK, 0 rows affected (0.27 sec)
    
    mysql> show variables like '%slow%';
    +---------------------+------------------------------------------+
    | Variable_name       | Value                                    |
    +---------------------+------------------------------------------+
    | log_slow_queries    | OFF                                      |
    | slow_launch_time    | 2                                        |
    | slow_query_log      | OFF                                      |
    | slow_query_log_file | /mysqllog/slow_log/slow_queries_3306.log |
    +---------------------+------------------------------------------+
    4 rows in set (0.00 sec)
    

    重命名旧的慢查询日志

    mv slow.log slow.log.01
    

    或者重新设置一个慢查询日志路径

    mysql> set global slow_query_log_file='/mysqllog/slow_log/slow_queries_3306_new.log';
    Query OK, 0 rows affected (0.03 sec)
    

    开启慢查询日志功能

    mysql> set global slow_query_log=1;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> show variables like '%slow%';
    +---------------------+----------------------------------------------+
    | Variable_name       | Value                                        |
    +---------------------+----------------------------------------------+
    | log_slow_queries    | ON                                           |
    | slow_launch_time    | 2                                            |
    | slow_query_log      | ON                                           |
    | slow_query_log_file | /mysqllog/slow_log/slow_queries_3306_new.log |
    +---------------------+----------------------------------------------+
    4 rows in set (0.00 sec)
    
  • 相关阅读:
    1657: [Usaco2006 Mar]Mooo 奶牛的歌声
    1610: [Usaco2008 Feb]Line连线游戏
    1660: [Usaco2006 Nov]Bad Hair Day 乱发节
    bzoj1207 [HNOI2004]打鼹鼠
    bzoj1046 [HAOI2007]上升序列
    bzoj3594 [Scoi2014]方伯伯的玉米田
    bzoj1878 [SDOI2009]HH的项链
    bzoj1293 [SCOI2009]生日礼物
    bzoj3211 花神游历各国
    bzoj3038 上帝造题的七分钟2
  • 原文地址:https://www.cnblogs.com/mrnx2004/p/11838314.html
Copyright © 2011-2022 走看看