MySQL Binlog详解

MySQL Binlog详解


  Mysql的binlog日志作用是用来记录mysql内部增删改查等对mysql数据库有更新的内容的记录(对数据库的改动),对数据库的查询select或show等不会被binlog日志记录;主要用于数据库的主从复制以及增量恢复。mysql的binlog日志必须打开log-bin功能才能生存binlog日志

-rw-rw—- 1 mysql mysql   669 8月  10 21:29 mysql-bin.000001
-rw-rw—- 1 mysql mysql   126 8月  10 22:06 mysql-bin.000002
-rw-rw—- 1 mysql mysql 11799 8月  15 18:17 mysql-bin.000003

1、打开MySQL的log-bin功能编辑my.cnf配置文件

vi /etc/mysql/mysql.conf.d/mysqld.cnf

server-id               = 1
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
binlog_do_db            = test
#binlog_ignore_db       = include_database_name

查看是否启用了日志

mysql>show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.00 sec)

# ls /var/log/mysql/
error.log  mysql-bin.000001

Leave a Reply

Your email address will not be published. Required fields are marked *