项目上线后浏量很小, 设置主从同步后发现从库产生大量的中继日志, 特别是晚上基本每隔几分钟就会产生一个日志, 查看mysql从库日志发现大量例似下面的信息:2019-12-07 02:22:32 13406 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
看样子是从库重新连接造成的; 我这主要是因为两个配置项造成的:
slave_net_timeout
MySQL主从复制的时候, 当Master和Slave之间的网络中断,但是Master和Slave无法察觉的情况下(比如防火墙或者路由问题)。Slave会等待slave_net_timeout设置的秒数后,才能认为网络出现故障,然后才会重连并且追赶这段时间主库的数据。
master_heartbeat_period
设置复制心跳的周期,取值范围为0 到 4294967秒。精确度可以达到毫秒,最小的非0值是0.001秒。心跳信息由master在主机binlog日志文件在设定的间隔时间内没有收到新的事件时发出,以便slave知道master是否正常。
默认值为slave_net_timeout的值除以2,设置为0表示完全的禁用心跳。
如果心跳参数master_heartbeat_period大于slave_net_timeout, 且主库当前没有DML/DDL等操作, 就会导致从库每隔slave_net_timeout设置的时间后重新连接主库, 产生一条新的relay_log。
解决方法:在从库上将心跳参数设置成小于slave_net_timeout:stop slave;
change master to master_heartbeat_period = 150;
set global slave_net_timeout = 300;
start slave;