二进制日志 Binary Log

1 什么是 binary log
二进制日志包含 “events”。这些“events” 描述了数据库的变更,例如创建数据表的操作,或者表数据的变革。如果使用的不是基于行的日志,二进制日志同时也包含那些 “有可能”改变数据表的“events”,例如 没有匹配任何 的 DELETE 语句。它也包含每条语句更新数据所花费的时间。

The binary log contains “events” that describe database changes such as table creation operations or changes to table data. It also contains events for statements that potentially could have made changes (for example, a DELETE which matched no rows), unless row-based logging is used. The binary log also contains information about how long each statement took that updated data

2 binary log 的用途
A 复制。 master server 的 bin-log 记载了 master server 的 数据变更记录,这个变更记录随后被发送给 slave servers, slave servers 执行这些变更,使得自身数据与 master server 数据一致

B 数据恢复。 当一个备份被恢复后,在 备份恢复后的 “events”需要重新执行

bin-log 不会记录 SELECT 和 SHOW 之类 对数据没有修改的的语句
bin-log 使得服务器的性能有轻微下降,但是相对于通过它 进行 复制和恢复带来的好处,开启bin-log是完全值得的

The binary log has two important purposes:
A: For replication, the binary log on a master replication server provides a record of the data changes to be sent to slave servers. The master server sends the events contained in its binary log to its slaves, which execute those events to make the same data changes that were made on the master. See Section 18.2, “Replication Implementation”.

B : Certain data recovery operations require use of the binary log.
After a backup has been restored, the events in the binary log that
were recorded after the backup was made are re-executed. These events
bring databases up to date from the point of the backup. See Section
8.5, “Point-in-Time (Incremental) Recovery Using the Binary Log”.

3 开启 binary log

step1 查看是否开启

mysql> show variables like  '%bin%';
+-----------------------------------------+----------------------+
| 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                                 | OFF                  |
| 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)

step2 开启
修改 mysql 配置文件并重启服务器

log_bin = mysql_bin

或者附加 –log-bin[=base_name] 选项重启服务器

mysqld --log-bin=mysql_bin restart

step3

mysql> show variables like  '%bin%';
+-----------------------------------------+----------------------+
| 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_</
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值