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 server-id=2

mkdir /var/lib/mysql-bin #chown mysql.mysql /var/lib/mysql-bin/ #systemctl restart mysqld

注:

  1. 重启mysqld 会截断

  2. flush logs 会截断

  3. reset master 删除所有binlog rm -rf /

  4. 删除部分 PURGE BINARY LOGS TO 'mysql-bin.010'; PURGE BINARY LOGS BEFORE '2016-04-02 22:46:26';

  5. 暂停 仅当前会话 SET SQL_LOG_BIN=0; SET SQL_LOG_BIN=1;

  6. 截取binlog all: 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 --stop-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);