核心问题是 MySQL 8.0 从库因机房断电导致 relay log(中继日志)文件损坏 / 丢失,进而引发复制元数据结构初始化失败(错误码 13124),最终导致主从复制进程(IO/SQL 线程)无法正常启动。错误日志中 “Error looking for file after /data/mysql/mysql3306/log/3306-relay-bin.000039” 也印证了 relay log 文件异常是根因,而那些 “deprecated” 警告仅为参数过时提示,不影响本次复制故障的核心解决。

1. 从库报错

1.1 show slave 报错

root@127.0.0.1 :(none) 02:29:38>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 10.4.0.108
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 5
              Master_Log_File: 3306-bin.000013
          Read_Master_Log_Pos: 107626352
               Relay_Log_File: 3306-relay-bin.000038
                Relay_Log_Pos: 107625935
        Relay_Master_Log_File: 3306-bin.000013
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 13124
                   Last_Error: Replica failed to initialize applier metadata structure from the repository
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 107625721
              Relay_Log_Space: 0
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 13124
               Last_SQL_Error: Replica failed to initialize applier metadata structure from the repository
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 0
                  Master_UUID: bcd50615-d4fd-11f0-9596-566ff5b6001c
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 260121 14:23:55
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: bcd50615-d4fd-11f0-9596-566ff5b6001c:1-18934463
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.01 sec)

ERROR: 
No query specified
View Code

1.2 Error Log 报错

MySQL8.0 ,机房断电后,开启从库报错:
错误日志:
rve_commit_order instead.
2026-01-21T10:11:31.496705+08:00 0 [Warning] [MY-011068] [Server] The syntax 'sync_master_info' is deprecated and will be removed in a future release. Please use sync_source_info instead.
2026-01-21T10:11:31.496718+08:00 0 [Warning] [MY-011070] [Server] '--sync-relay-log-info' is deprecated and will be removed in a future release.
2026-01-21T10:11:31.496731+08:00 0 [Warning] [MY-011069] [Server] The syntax '--master-info-repository' is deprecated and will be removed in a future release.
2026-01-21T10:11:31.496742+08:00 0 [Warning] [MY-011069] [Server] The syntax '--relay-log-info-repository' is deprecated and will be removed in a future release.
2026-01-21T10:11:31.496754+08:00 0 [Warning] [MY-011068] [Server] The syntax 'log_slave_updates' is deprecated and will be removed in a future release. Please use log_replica_updates instead.
2026-01-21T10:11:31.496766+08:00 0 [Warning] [MY-011068] [Server] The syntax 'slave_net_timeout' is deprecated and will be removed in a future release. Please use replica_net_timeout instead.
2026-01-21T10:11:31.496790+08:00 0 [Warning] [MY-010086] [Server] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2026-01-21T10:11:31.496811+08:00 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2026-01-21T10:11:31.496859+08:00 0 [Warning] [MY-010097] [Server] Insecure configuration for --secure-log-path: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2026-01-21T10:11:31.496909+08:00 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2026-01-21T10:11:31.496945+08:00 0 [System] [MY-010116] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.42-33) starting as process 3725
2026-01-21T10:11:31.518628+08:00 0 [Warning] [MY-013267] [InnoDB] The setting INNODB_UNDO_TABLESPACES is deprecated and is no longer used.  InnoDB always creates 2 undo tablespaces to start with. If you need more, please use CREATE UNDO TABLESPACE.
2026-01-21T10:11:31.518662+08:00 0 [Warning] [MY-013907] [InnoDB] Deprecated configuration parameters innodb_log_file_size and/or innodb_log_files_in_group have been used to compute innodb_redo_log_capacity=3221225472. Please use innodb_redo_log_capacity instead.
2026-01-21T10:11:31.525342+08:00 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-01-21T10:11:34.812539+08:00 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-01-21T10:11:43.147320+08:00 0 [Warning] [MY-010918] [Repl] 'rpl_semi_sync_master' is deprecated and will be removed in a future release. Please use rpl_semi_sync_source instead.
2026-01-21T10:11:43.147392+08:00 0 [Warning] [MY-010918] [Repl] 'rpl_semi_sync_slave' is deprecated and will be removed in a future release. Please use rpl_semi_sync_replica instead.
2026-01-21T10:11:43.965952+08:00 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2026-01-21T10:11:43.977383+08:00 0 [System] [MY-010232] [Server] XA crash recovery finished.
2026-01-21T10:11:44.740464+08:00 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2026-01-21T10:11:44.740492+08:00 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2026-01-21T10:11:44.772589+08:00 0 [ERROR] [MY-010575] [Repl] Error looking for file after /data/mysql/mysql3306/log/3306-relay-bin.000039.
2026-01-21T10:11:44.772866+08:00 0 [ERROR] [MY-010426] [Repl] Replica: Failed to initialize the connection metadata structure for channel ''; its record may still be present in the applier metadata repository, consider deleting it.
2026-01-21T10:11:44.772879+08:00 0 [ERROR] [MY-010529] [Repl] Failed to create or recover replication info repositories.
2026-01-21T10:11:44.776827+08:00 0 [System] [MY-010931] [Server] /opt/mysql/bin/mysqld: ready for connections. Version: '8.0.42-33'  socket: '/data/mysql/mysql3306/log/3306.sock'  port: 3306  Percona Server (GPL), Release 33, Revision 9dc49998.
2026-01-21T10:11:44.776853+08:00 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2026-01-21T14:23:26.242853+08:00 9 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
2026-01-21T14:23:55.370167+08:00 9 [ERROR] [MY-013124] [Repl] Replica SQL for channel '': Replica failed to initialize applier metadata structure from the repository, Error_code: MY-013124

 

2. 解决方案一

2.1. 登录从库 MySQL 并停止复制进程

首先停止异常的复制进程,避免进一步的元数据冲突:
 
-- MySQL8.0兼容旧命令,也可以用 STOP REPLICA;
STOP SLAVE;

2.2. 重置复制元数据(核心步骤)

执行RESET SLAVE ALL清除损坏的 relay log 文件和错误的复制元数据(该命令会删除所有 relay log 文件、清空复制配置表,是解决此类断电导致复制元数据不一致的关键):
-- 重置所有复制相关配置和relay log,注意:该命令会清除主从连接信息,后续需重新配置
RESET SLAVE ALL;

2.3. 重新配置主从复制连接

根据你的环境选择以下两种方式(优先推荐 GTID 自动定位):
方式 1:GTID 自动定位(推荐,你的环境已开启 GTID)
从库执行以下命令(替换你的repl用户密码为实际密码):
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='10.4.0.108',        -- 主库IP
SOURCE_USER='repl',              -- 复制专用用户
SOURCE_PASSWORD='你的repl用户密码', -- 复制用户密码
SOURCE_PORT=3306,                -- 主库端口
SOURCE_AUTO_POSITION=1;          -- 开启GTID自动定位,无需手动指定binlog位置
方式 2:手动指定 binlog 位置(无 GTID 时使用)
如果主库未开启 GTID,需先登录主库查询当前 binlog 状态:
-- 主库执行,获取File和Position值
SHOW MASTER STATUS;
再回到从库执行(替换占位符为实际值):
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='10.4.0.108',
SOURCE_USER='repl',
SOURCE_PASSWORD='你的repl用户密码',
SOURCE_PORT=3306,
SOURCE_LOG_FILE='3306-bin.000013',  -- 主库SHOW MASTER STATUS的File值
SOURCE_LOG_POS=107626352;           -- 主库SHOW MASTER STATUS的Position值

2.4. 启动复制进程并验证

-- MySQL8.0推荐用START REPLICA,兼容旧的START SLAVE
START REPLICA;

-- 检查复制状态
SHOW REPLICA STATUS\G;
 
验证关键点:
  • Slave_IO_RunningSlave_SQL_Running 均为 Yes
  • Last_SQL_Error 为空
  • Seconds_Behind_Master 显示具体数值(非 NULL)

2.5. (可选)修复过时参数警告

虽然不影响本次故障,但为了长期兼容性,建议修改从库my.cnf(或my.ini)配置文件,替换过时参数:
 
过时参数新参数
sync_master_info sync_source_info
log_slave_updates log_replica_updates
slave_net_timeout replica_net_timeout
master-info-repository 移除(8.0 默认表存储)
rpl_semi_sync_slave rpl_semi_sync_replica
 
修改后重启 MySQL 生效(需业务低峰期操作)。

3. 解决方案二(部分场景有效)

3.1.预防性配置 + 重启(作为补充方案)

在 my.cnf 配置文件中添加:

ini
# 核心配置
[mysqld]
# 允许MySQL启动时自动启动复制进程
skip_replica_start = OFF  # MySQL 8.0 新语法
# skip_slave_start = OFF   # 过时语法,不推荐

# 自动恢复relay log(重启时删除损坏的中继日志,从主库重新获取)
relay_log_recovery = 1

# 复制网络超时(避免网络波动导致复制中断)
replica_net_timeout = 60
# slave_net_timeout = 60   # 过时语法,不推荐

# 复制元数据存储方式(确保使用表存储,默认已开启)
# master_info_repository = TABLE    # 过时,无需配置
# relay_log_info_repository = TABLE # 过时,无需配置

重启MySQL:

bash
# 重启MySQL服务
systemctl restart mysql3306  # 根据实际服务名调整

4. 总结

  1. 核心根因:断电导致 relay log 损坏,复制元数据(slave_master_info/slave_relay_log_info 表)与实际文件不一致,引发初始化失败。
  2. 关键操作:通过RESET SLAVE ALL清空损坏的复制元数据和 relay log,重新配置主从连接后启动复制。
  3. 验证标准:复制 IO/SQL 线程均为 Yes、无错误日志、延迟值正常,代表主从复制恢复。
如果执行过程中提示权限问题,需确保主库的repl用户拥有REPLICATION SLAVE权限(主库执行GRANT REPLICATION SLAVE ON *.* TO 'repl'@'从库IP' IDENTIFIED BY '密码';)。
 posted on 2026-01-21 15:37  xibuhaohao  阅读(2)  评论(0)    收藏  举报