Mysql系统变量系列之(二)Binary Logging

1. 开启二进制日志:--log-bin[=base_name]

PropertyValue
Command-Line Format--log-bin=file_name
TypeFile name

    Enables binary logging. With binary logging enabled, the server logs all statements that change data to the binary log, which is used for backup and replication.

    开启二进制日志选项后,会将修改数据的statement记录在日志文件中去。

    In MySQL 5.7, the base name defaults to host_name-bin.

2. 二进制日志索引文件:--log-bin-index[=file_name]

PropertyValue
Command-Line Format--log-bin-index=file_name
System Variablelog_bin_index
ScopeGlobal
DynamicNo
TypeFile name

    The name for the binary log index file, which contains the names of the binary log files. By default, it has the same location and base name as the value specified for the binary log files using the --log-bin option, plus the extension .index. If you do not specify --log-bin, the default binary log index file name is binlog.index. If you omit the file name and do not specify one with --log-bin, the default binary log index file name is host_name-bin.index, using the name of the host machine.

3. 校验和:--binlog-checksum={NONE|CRC32}

PropertyValue
Command-Line Format--binlog-checksum=type
TypeString
Default ValueCRC32
Valid Values

NONE

CRC32

    Enabling this option causes the master to write checksums for events written to the binary log.

    将事件的校验和写入到二进制日志文件中。

4. master 开启校验和验证:master_verify_checksum

PropertyValue
Command-Line Format--master-verify-checksum[={OFF|ON}]
System Variablemaster_verify_checksum
ScopeGlobal
DynamicYes
TypeBoolean
Default ValueOFF

    Enabling this variable causes the master to verify events read from the binary log by examining checksums, and to stop with an error in the event of a mismatch.

    master从日志文件中读取事件时,会进行校验和验证。如果校验和不匹配,则停止读取事件,抛出错误信息。

5. slave开启校验和验证:--slave-sql-verify-checksum[={OFF|ON}]

PropertyValue
Command-Line Format--slave-sql-verify-checksum[={OFF|ON}]
TypeBoolean
Default ValueON

    When this option is enabled, the slave examines checksums read from the relay log, in the event of a mismatch, the slave stops with an error.

    slave从中继日志中读取事件时,会对校验和进行验证,匹配失败则停止SQL Thread线程的执行,抛出错误信息。

6. 是否将statement语句记录进行日志文件中:--binlog-rows-query-log-events[={OFF|ON}]

PropertyValue
Command-Line Format--binlog-rows-query-log-events[={OFF|ON}]
System Variablebinlog_rows_query_log_events
ScopeGlobal, Session
DynamicYes
TypeBoolean
Default ValueOFF

    This system variable affects row-based logging only. When enabled, it causes the server to write informational log events such as row query log events into its binary log. 

    针对binlog_format=row的配置有效,将原始的statement语句写入到二进制文件中。

    To view them, increase the verbosity level by using mysqlbinlog's --verbose option twice, either as -vv or --verbose --verbose.

7. 日志文件的过期时间:--expire-logs-days

PropertyValue
Command-Line Format--expire-logs-days=#
System Variableexpire_logs_days
ScopeGlobal
DynamicYes
TypeInteger
Default Value0
Minimum Value0
Maximum Value99

    The number of days for automatic binary log file removal. The default is 0, which means “no automatic removal.”

    日志文件超过X天后,会被自动移除。

7. 单个日志文件的最大值:--max-binlog-size

PropertyValue
Command-Line Format--max-binlog-size=#
System Variablemax_binlog_size
ScopeGlobal
DynamicYes
TypeInteger
Default Value1073741824
Minimum Value4096
Maximum Value1073741824

    If a write to the binary log causes the current log file size to exceed the value of this variable, the server rotates the binary logs (closes the current file and opens the next one). The minimum value is 4096 bytes. The maximum and default value is 1GB.

8. 刷新二进制日志文件到磁盘的频率:--sync-binlog

PropertyValue
Command-Line Format--sync-binlog=#
System Variablesync_binlog
ScopeGlobal
DynamicYes
TypeInteger
Default Value (>= 5.7.7)1
Default Value (<= 5.7.6)0
Minimum Value0
Maximum Value4294967295

Controls how often the MySQL server synchronizes the binary log to disk.

  • sync_binlog=0: Disables synchronization of the binary log to disk by the MySQL server. Instead, the MySQL server relies on the operating system to flush the binary log to disk from time to time as it does for any other file. 禁用mysql server刷新日志到磁盘的功能,日志刷新策略依赖操作系统的刷新机制。

  • sync_binlog=1: Enables synchronization of the binary log to disk before transactions are committed. This is the safest setting but can have a negative impact on performance due to the increased number of disk writes. 在事务提交之前,刷新日志到磁盘,但是这种模式对性能有影响。

  • sync_binlog=N, where N is a value other than 0 or 1: The binary log is synchronized to disk after N binary log commit groups have been collected. 在N个事务提交之后,将日志文件刷新到磁盘;

For the greatest possible durability and consistency in a replication setup that uses InnoDB with transactions, use these settings:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值