mysql-日誌管理
/etc/my.cnf
error log 錯誤日誌 排錯 /var/log/mysqld.log【默認開啟】
bin log 二進制日誌 備份 增量備份 DDL DML DCL
Relay log 中繼日誌 復制 接收 replication master
slow log 慢查詢日誌 調優 查詢時間超過指定值
Error Log
log-error=/var/log/mysqld.log
Binary Log
log-bin=/var/log/mysql-bin/slave2
mkdir /var/lib/mysql-bin
#chown mysql.mysql /var/lib/mysql-bin/
#systemctl restart mysqld
註:
- 重啟mysqld 會截斷
- flush logs 會截斷
- reset master 刪除所有binlog rm -rf /
-
刪除部分
PURGE BINARY LOGS TO ‘mysql-bin.010‘;
PURGE BINARY LOGS BEFORE ‘2016-04-02 22:46:26‘; -
暫停 僅當前會話
SET SQL_LOG_BIN=0;
SET SQL_LOG_BIN=1; - 截取binlog
mysqlbinlog mysql.000002
datetime:
#mysqlbinlog mysql.000002 --start-datetime="2018-12-05 10:02:56"
#mysqlbinlog mysql.000002 --stop-datetime="2018-12-05 11:02:54"
#mysqlbinlog mysql.000002 --start-datetime="2018-12-05 10:02:56" --stop-datetime="2018-12-05 11:02:54"
position:
#mysqlbinlog mysql.000002 --start-position=260
#mysqlbinlog mysql.000002 --start-position=260 --stop-position=930
Slow Query Log
slow_query_log=1
slow_query_log_file=/var/log/mysql-slow/slow.log
long_query_time=3
#mkdir /var/log/mysql-slow/
#chown mysql.mysql /var/log/mysql-slow/
#systemctl restart mysqld
查看慢查詢日誌
測試:BENCHMARK(count,expr)
SELECT BENCHMARK(50000000,2*3);
mysql-日誌管理