mysql> show global variables like "log_error"; +---------------+--------------------------+ | Variable_name | Value | +---------------+--------------------------+ | log_error | /var/log/mysql/error.log | +---------------+--------------------------+ 1 row in set (0.00 sec) ##tail -f error.log 實時監控這個文件中的;tail -f error.log 實時監控這個文件中的; 慢查詢日志
mysql> show global variables like '%slow%'; +---------------------+----------------------------------+ | Variable_name | Value | +---------------------+----------------------------------+ | log_slow_queries | OFF | | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | /var/lib/mysql/itcast01-slow.log | +---------------------+----------------------------------+ 4 rows in set (0.00 sec)#打開慢查詢日志
mysql> set global slow_query_log =1; Query OK, 0 rows affected (0.00 sec) mysql> show global variables like '%slow%'; +---------------------+----------------------------------+ | Variable_name | Value | +---------------------+----------------------------------+ | log_slow_queries | ON | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /var/lib/mysql/itcast01-slow.log | +---------------------+----------------------------------+ 4 rows in set (0.00 sec)
#查看慢查詢日志的阈值
mysql> show global variables like 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+
設置阈值,通常5秒;
mysql> set global long_query_time = 1; Query OK, 0 rows affected (0.00 sec) mysql> show global variables like 'long_query_time'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 1.000000 | +-----------------+----------+ 1 row in set (0.00 sec)
綜合查詢日志
mysql> show global variables like '%general%'; +------------------+-----------------------------+ | Variable_name | Value | +------------------+-----------------------------+ | general_log | OFF | | general_log_file | /var/lib/mysql/itcast01.log | +------------------+-----------------------------+ 2 rows in set (0.00 sec)查詢日志的輸出與文件切換
mysql> show global variables like '%log_output%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | FILE | +---------------+-------+ 1 row in set (0.00 sec)
存儲引擎事務日志---只記錄數據變化;
情況二:
所以在寫入頻繁的線上業務中,建議將ib_logfile的大小調大;這樣有利於並發; 二進制日志binlog
mysql> show global variables like 'log_bin'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | OFF | +---------------+-------+ 1 row in set (0.00 sec)
binlog管理
show binary logs; show binlog events in 'mysql-bin.000001'
binlog 只記錄對數據產生變化的 語句; 但是有局限: 如果使用uuid(),每次產生不一樣的值;來插入數據, binlog,記錄的是 insert into tab values (uuid()); 此時通過回放,binlog不能得到原數據; 因為每次uuid()產生不一樣的值。 所以mysql允許使用另一種格式記錄binlog,只記錄數據變化值; 可以將binlog_format 設置成row; 而binlog_format 設置成satement,記錄具體操作語句; 而binlog_format 設置成mixed,mysql自動判斷使用row,還是satement; 總結