「MySQL」- binlog

Binlog,日志文件,其包含描述数据库变更的事件;

实际作用
1)数据库复制
2)数据恢复

MySQL 8.0

启用

WIP

删除

https://dev.mysql.com/doc/refman/8.4/en/purge-binary-logs.html
PURGE BINARY LOGS BEFORE ‘2021-01-01 00:00:00’;
PURGE BINARY LOGS TO ‘mysql-bin.12345’;

修改

WIP

查看

https://dev.mysql.com/doc/refman/8.4/en/show-binary-logs.html
SHOW BINARY LOGS;

https://dev.mysql.com/doc/refman/8.4/en/show-binlog-events.html
SHOW BINLOG EVENTS

相关工具

mysqlbinlog — Utility for Processing Binary Log Files
https://dev.mysql.com/doc/refman/8.4/en/mysqlbinlog.html

相关参数

binlog_expire_logs_seconds | in Seconds | Default=2592000 |https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds

binlog_expire_logs_auto_purge | ON/OFF | https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_auto_purge

MySQL 5.7

MySQL 5.6 Reference Manual/Binary Log Options and Variables
MySQL 5.7 Reference Manual/Replication and Binary Logging Options and Variables
MySQL 5.6 Reference Manual/The Binary Log

启用 binlog 功能

修改数据库配置文件:

[mysqld]
server_id = 26
log_bin = /var/log/mysql/binlog

binlog_format = MIXED
expire_logs_days = 30
max_binlog_size = 500M
sync_binlog = 1

查看 binlog 内容

使用 mysqlbinlog 可以文件内容:

mysqlbinlog --base64-output=decode-rows -vv '/path/to/binlog/file'