zoukankan      html  css  js  c++  java
  • mysql general log 查看mysql 运行历史

    我们有时候须要查看mysql的运行历史,比方我们做sql优化的时候,起码要知道运行的sql是什么。框架通常会帮我们拼装sql,所以在程序中不一定能够打印出sql,这个时候就须要mysql的general
    log了。


    查看设置mysql genneral log

    show VARIABLES like '%general_log%';
    
    set GLOBAL general_log = off;// on-打开; off-关闭
    
    general_log ON
    general_log_file    /var/log/mysql/query.log
    

    使用mysql general log

    tail -f /path/to/log/query.log | grep yourtable
    13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2)
            13518 Query DESCRIBE `babysitter_tips`
            13518 Close stmt
            13518 Prepare   SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5
            13518 Reset stmt
            13518 Close stmt
            13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2) AND (tip_id > 15440)
            13518 Close stmt
            13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2)
            13518 Query DESCRIBE `babysitter_tips`
            13518 Close stmt
            13518 Prepare   SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5
            13518 Reset stmt
            13518 Close stmt
            13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2) AND (tip_id > '')
            13518 Close stmt
            13518 Prepare   SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '2') AND (is_enable = 1) AND (is_tip = 2)
            13518 Query DESCRIBE `babysitter_tips`
            13518 Close stmt
            13518 Prepare   SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '2') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5
            13518 Reset stmt
            13518 Close stmt

    清理mysql general log

    general log会比較大,所以默认市关闭的,所以最好须要的时候打开,随手关闭。假设发现query.log过大。能够手动删除。在general log打开的情况下,query.log文件相似于mysql表的lock情况,不同意改动和删除。关闭general log就能够操作了。

  • 相关阅读:
    接口的显示实现和隐式实现
    Math.Round和四舍五入
    经典SQL语句大全(转)
    简明添加log4net到项目中
    NAnt学习笔记(3) Properties, Loggers & Listeners
    (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
    Pyramid中如何配置多种URL匹配同一个View
    《IT项目管理》读书笔记(4) —— 项目范围管理
    C#语法糖
    枚举类型转换成字符串
  • 原文地址:https://www.cnblogs.com/llguanli/p/8708432.html
Copyright © 2011-2022 走看看