設定和查詢mysql錯誤日誌、訪問日誌
阿新 • • 發佈:2019-02-12
日誌型別
mysql有以下幾種日誌:
錯誤日誌: log_err
查詢日誌: log
慢查詢日誌: log_slow-queries
更新日誌: log_update
二進位制日誌: log_bin
命令
檢視是否啟用了日誌
mysql> show variables like 'log_bin';
怎樣知道當前的日誌
mysql> show master status;
展示二進位制日誌數目
mysql> show master logs;
看二進位制日誌檔案用mysqlbinlog
shell> mysqlbinlog mail-bin.000001
配置檔案
在配置檔案中指定log的輸出位置.
Linux:Linux 的配置檔案為 my.cnf ,一般是
/etc/mysql/my.cnf
日誌檔案型別概述
錯誤日誌
記錄啟動、執行或停止mysqld時出現的問題。
my.cnf配置資訊:
#Enter a name for the error log file. Otherwise a default name will be used.
log_error=/log/mysql/mysql_log_error
查詢日誌
記錄建立的客戶端連線和執行的語句。
my.cnf配置資訊:
#Enter a name for the query log file. Otherwise a default name will be used.
log=/log/mysql/mysql_log
更新日誌
記錄更改資料的語句,不贊成使用該日誌。
請注意,增加了這個配置後,mysql不能啟動。暫時沒有解決該問題。
my.cnf配置資訊:
#Enter a name for the update log file. Otherwise a default name will be used.
log_update=/log /mysql/mysql_log_update
二進位制日誌
記錄所有更改資料的語句,還用於複製。
my.cnf配置資訊:
#Enter a name for the binary log. Otherwise a default name will be used.
log_bin=/log/mysql/mysql_log_bin
慢日誌
記錄所有執行時間超過long_query_time秒的所有查詢或不使用索引的查詢。
my.cnf配置資訊:
#Enter a name for the slow query log file. Otherwise a default name will be used.
long_query_time=2
log_slow-queries=/log/mysql/mysql_log_slow