mysql relay log参数汇总

前言:MySQL进行主主复制或主从复制的时候会在配置文件制定的目录下面产生相应的relay log,本文档总结这些相关参数的定义及解释。

1、什么是relay log

The relay log, like the binary log, consists of a set of numbered files containing events that describe database changes, and an index file that contains the names of all used relay log files.

The term relay log file” generally denotes an individual numbered file containing database events. The term relay log” collectively denotes the set of numbered relay log files plus the index file.

Relay log files have the same format as binary log files and can be read using mysqlbinlog .

理解:relay log很多方面都跟binary log差不多,区别是:从服务器I/O线程将主服务器的二进制日志读取过来记录到从服务器本地文件,然后SQL线程会读取relay-log日志的内容并应用到从服务器。

2、relay log的相关参数

mysql> show variables like '%relay%';
+---------------------------+----------------------------------------------+
| Variable_name             | Value                                        |
+---------------------------+----------------------------------------------+
| max_relay_log_size        | 0                                            |
| relay_log                 | /data01/mysql_dir/data/mysql-relay-bin       |
| relay_log_basename        | /data01/mysql_dir/data/mysql-relay-bin       |
| relay_log_index           | /data01/mysql_dir/data/mysql-relay-bin.index |
| relay_log_info_file       | /data01/mysql_dir/data/mysql-relay-bin.info  |
| relay_log_info_repository | TABLE                                        |
| relay_log_purge           | ON                                           |
| relay_log_recovery        | ON                                           |
| relay_log_space_limit     | 0                                            |
| sync_relay_log            | 10000                                        |
| sync_relay_log_info       | 10000                                        |
+---------------------------+----------------------------------------------+
11 rows in set (0.00 sec)

2.1  max_relay_log_size:标记relay log 允许的最大值,如果该值为0,则默认值为max_binlog_size(1G);如果不为0,则max_relay_log_size则为最大的relay_log文件大小;

2.2  relay_log:定义relay_log的位置和名称,如果值为空,则默认位置在数据文件的目录,文件名为host_name-relay-bin.nnnnnn(By default, relay log file names have the form host_name-relay-bin.nnnnnn in the data directory);

2.3 relay_log_index:同relay_log,定义relay_log的位置和名称;

2.4 relay_log_info_file:设置relay-log.info的位置和名称(relay-log.info记录MASTER的binary_log的恢复位置和relay_log的位置),也可以配置记录到mysql库中的slave_relay_log_info表中;

2.5 relay_log_purge:是否自动清空不再需要中继日志时。默认值为1(启用)。

2.6 relay_log_recovery:当slave从库宕机后,假如relay-log损坏了,导致一部分中继日志没有处理,则自动放弃所有未执行的relay-log,并且重新从master上获取日志,这样就保证了relay-log的完整性。默认情况下该功能是关闭的,将relay_log_recovery的值设置为 1时,可在slave从库上开启该功能,建议开启。开启该参数后,记得开启relay-log-purge参数。

This variable also interacts with relay-log-purge, which controls purging of logs when they are no longer needed. Enabling the --relay-log-recovery option when relay-log-purge is disabled risks reading the relay log from files that were not purged, leading to data inconsistency, and is therefore not crash-safe.

 

2.7 relay_log_space_limit:防止中继日志写满磁盘,这里设置中继日志最大限额。但此设置存在主库崩溃,从库中继日志不全的情况,不到万不得已,不推荐使用;

2.8 sync_relay_log:这个参数和sync_binlog是一样的,当设置为1时,slave的I/O线程每次接收到master发送过来的binlog日志都要写入系统缓冲区,然后刷入relay log中继日志里,这样是最安全的,因为在崩溃的时候,你最多会丢失一个事务,但会造成磁盘的大量I/O。当设置为0时,并不是马上就刷入中继日志里,而是由操作系统决定何时来写入,虽然安全性降低了,但减少了大量的磁盘I/O操作。这个值默认是10000,可动态修改,建议采用默认值。

2.9 sync_relay_log_info:这个参数和sync_relay_log参数一样,当设置为1时,slave的I/O线程每次接收到master发送过来的binlog日志都要写入系统缓冲区,然后刷入relay-log.info里,这样是最安全的,因为在崩溃的时候,你最多会丢失一个事务,但会造成磁盘的大量I/O。当设置为0时,并不是马上就刷入relay-log.info里,而是由操作系统决定何时来写入,虽然安全性降低了,但减少了大量的磁盘I/O操作。这个值默认是10000,可动态修改,建议采用默认值。

 

参考:

http://www.linuxidc.com/Linux/2014-11/109032.htm

http://dev.mysql.com/doc/refman/5.7/en/slave-logs-relaylog.html

http://dev.mysql.com/doc/refman/5.7/en/replication-options-slave.html

posted on 2016-05-11 14:18  Still water run deep  阅读(2971)  评论(0编辑  收藏  举报

导航