mysql从库同步数据失败,slave功能无法启用
mysql> start slave; ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository查看错误日志提示如下:
[ERROR] [MY-010544] [Repl] Failed to open the relay log './e4917fb8ce7c-relay-bin.000014' (relay_log_pos 371). 2020-10-20T05:19:46.694608Z 0 [ERROR] [MY-011059] [Repl] Could not find target log file mentioned in relay log info in the index file '/usr/local/mysql/data/e4917fb8ce7c-relay-bin.index' during relay log initialization. 2020-10-20T05:19:46.695814Z 0 [ERROR] [MY-010426] [Repl] Slave: Failed to initialize the master info structure for channel ''; its record may still be present in 'mysql.slave_master_info' table, consider deleting it. 2020-10-20T05:19:46.696492Z 0 [ERROR] [MY-010529] [Repl] Failed to create or recover replication info repositories.意思是找不到对应的relay-log文件,出现这个原因是因为主机名称发生了变化导致的,mysql默认的relaylog存储是以 hostname-relay-bin来存储的,如果使用了docker。那在重新启动新的容器会导致hostname发生变化而出现以上错误提示。这个错误在mysql文档中有提到(地址):
If a replica uses the default host-based relay log file names, changing a replica’s host name after replication has been set up can cause replication to fail with the errors Failed to open the relay log and Could not find target log during relay log initialization. This is a known issue (see Bug #2122). If you anticipate that a replica’s host name might change in the future (for example, if networking is set up on the replica such that its host name can be modified using DHCP), you can avoid this issue entirely by using the relay_log and relay_log_index system variables to specify relay log file names explicitly when you initially set up the replica. This causes the names to be independent of server host name changes.