mysql general log 查看mysql 運行曆史

來源:互聯網
上載者:User

標籤:gpo   mysq   oba   log   tor   grep   table   span   ack   

我們有時候須要查看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 ONgeneral_log_file    /var/log/mysql/query.log
使用mysql general log
tail -f /path/to/log/query.log | grep yourtable13518 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就能夠操作了。

mysql general log 查看mysql 運行曆史

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.