暂无图片
分享
杨豹
2019-09-11
mysql主从问题

您好!我请教一个mysql主从的问题。问题描述我已经上传到博客中了。https://www.cnblogs.com/ddzj01/p/11505968.html,希望抽空帮忙看看。

收藏
分享
7条回答
默认
最新
lps

是由 sync_master_info 这个参数控制的。

通过参数 sync_master_info 来设置备库经过多少个 binlog event 来更新已经读取到的位点信息。

暂无图片 评论
暂无图片 有用 0
lps

mysql> show variables like 'sync_master_info'

    -> ;

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| sync_master_info | 10000 |

+------------------+-------+

1 row in set (0.01 sec)

mysql>

这个参数默认是 10000,如果set global sync_master_info=1的话,理论上复制会更安全,但是这样的话执行每个event都要去update一次 mysql.slave_master_info,就增大了磁盘IO。

暂无图片 评论
暂无图片 有用 0
杨豹

您好,的确是这个参数影响的。但我还有疑问,sync_relay_log这个参数我看到是默认10000,按照文档上的说明,这个是控制从库多久写日志到slave log中。可我在主库做任何修改,从库的slave log都会立刻看到日志。而且在我停掉slave进程,强制重启从库的服务器,重新打开slave进程,事务都没有任何丢失。那么这个sync_relay_log参数又是啥呢?这是最后一个问题了。

暂无图片 评论
暂无图片 有用 0
lps

sync_relay_log 是控制 刷盘(fdatasync)的 默认值是10000,也就是10000个事物进行一次 fdatasync。

当然可以设置为1,这是最安全的,每次都刷新到磁盘,但是这样会占用大量的io。

https://dev.mysql.com/doc/refman/5.7/en/replication-options-slave.html#sysvar_sync_relay_log



If the value of this variable is greater than 0, the MySQL server synchronizes its relay log to disk (using fdatasync()) after every sync_relay_log events are written to the relay log. Setting this variable takes effect for all replication channels immediately, including running channels.

Setting sync_relay_log to 0 causes no synchronization to be done to disk; in this case, the server relies on the operating system to flush the relay log's contents from time to time as for any other file.

A value of 1 is the safest choice because in the event of a crash you lose at most one event from the relay log. However, it is also the slowest choice (unless the disk has a battery-backed cache, which makes synchronization very fast).


暂无图片 评论
暂无图片 有用 0
杨豹

你好,文档我之前也看到了。我的问题是我将sync_relay_log保持为它的默认值10000,但是仍然在主库每次有修改的时候,从库的slave log马上就能看到同步过来的日志。这个参数不是说每10000个event才写到磁盘上的吗

暂无图片 评论
暂无图片 有用 0
lps

都是先写 buffer 再刷盘的哈。

暂无图片 评论
暂无图片 有用 0
杨豹
问题已关闭: 问题已经得到解决
暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏