日志类型
1.[错误日志]
【参数】
log_error log_warnings = {1|0}
2.[查询日志]
【参数】
log # 是否开启查询日志
log_output # 输出地址
general_log {ON|OFF}
general_log_file
3.[慢查询日志]
#会找出查询较慢的sql,记录查询时间
[参数]
slow_query_log
slow_query_log_file
跟log_query_time 的参数有关,慢查的时长:包含进程阻塞时间,不一定指sql本身查询时间。
4.[事务日志]
[参数]
innodb_data_home_dir
innodb_log_files_in_group
innodb_log_file_size
innodb_log_buffer_size
innodb_flush_log_at_trx_commit #事务提交时是否立即将缓存信息写入到磁盘中
innodb_mirrored_log_groups # 日志组镜像
[文件名]
ib_logfile0, ib_logfile1
5.【中继日志】
6.【二进制日志】
记录修改数据或者有可能引起数据改变的mysql语句
bin-log是记录着mysql所有事件的操作,当mysql发生灾难性错误时,可以通过bin-log做完整恢复,基于时间点的恢复,和基于位置的恢复
[参数]
log_bin # 是否启用二进制日志
= /path/some_log_file ,不用后缀
= ON
sql_log_bin # 用于控制回话级别二进制日志功能的开启或关闭
max_binlog_size # 单个binlog 文件大小
binlog_cache_size
binlog_format
max_binlog_stmt_cache_size
max_binlog_cache_size
sync_binlog # 事务提交时,是否将事件从cache写入磁盘文件中
expire_logs_day #设置日志过期天数,过期后会自动删除
【日志文件】
mysql-bin.XXXXX
mysql-bin.index
[日志格式]
statement SQL语句
row 记录数据
mixed 混合前两种模式
[查看二进制日志]
MYSQL>SHOW {BINARY | MASTER} LOGS #查看二进制文件, 主服务器日志
mysql> show binary logs;
+---------------------+-----------+ | Log_name | File_size | +---------------------+-----------+ | mysql-bin.000001 | 29638 | | mysql-bin.000002 | 1062789 | | mysql-bin.000003 | 126 | | mysql-bin.000004 | 126 | | mysql-bin.000005 | 126 | | mysql-bin.000006 | 340 | | mysql-bin.000007 | 107 | +------------------+-----------+ 7 rows in set (0.09 sec)
mysql> show master status;
+---------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000006 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
【打开当前】
mysql> SHOW BINLOG EVENTS [ IN 'file' ] [ FROM pos [LIMIT [m,]n ]]
mysql> show binlog events in 'mysql-bin.000007';
【滚动日志】
mysql> FLUSH LOGS;
【清除二进制日志】
mysql>PURGE { BINARY |master } LOGS { TO 'log_name" | BEFORE datatime_expr }
+-------------------------------------------------------+------------------------------+ | Variable_name | Value | +-------------------------------------------------------+------------------------------+ | binlog_cache_size | 32768 | | binlog_direct_non_transactional_updates | OFF | | binlog_format | STATEMENT | | binlog_stmt_cache_size | 32768 | | innodb_locks_unsafe_for_binlog | OFF | | log_bin | ON | | log_bin_trust_function_creators | OFF | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | sql_log_bin | ON | | sync_binlog | 0 | +-----------------------------------------+------------+--------------------------------+ 12 rows in set (0.00 sec)
【命令行工具】
mysqlbinlog mysql-bin.000002
# mysqlbinlog --start-datetime=# --stop-datetime=# --start-position=# --stop-position=#