一、问题现象
环境如下:
角色 | IP |
master | 192.168.11.152 |
slave | 192.168.11.151 |
slave主机的主要错误:slave的IO线程无法正常连接到master,状态是Replica_IO_Running: No,主要错误信息如下:
mysql> show replica status\G; *************************** 1. row *************************** Replica_IO_State: Source_Host: 192.168.11.152 Source_User: syn_b Source_Port: 3306 Connect_Retry: 60 Source_Log_File: mysql-bin.000053 Read_Source_Log_Pos: 3908501 Relay_Log_File: zbx-db01-relay-bin.000143 Relay_Log_Pos: 4 Relay_Source_Log_File: mysql-bin.000053 Replica_IO_Running: No Replica_SQL_Running: Yes Source_SSL_Verify_Server_Cert: No Last_IO_Errno: 13114 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file' Last_SQL_Errno: 0 Last_SQL_Error: ...
❝关键错误代码:13114
❝关键错误信息:Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'(从二进制日志读取数据时,从 master 收到致命错误 1236:“在二进制日志索引文件中找不到第一个日志文件名”)
二、前期诊断
主要是通过关键的错误代码和关键的错误消息在网上搜索,参考链接如下:
- http://www.manongjc.com/detail/25-nefbhovgktkcfsq.html
- https://blog.csdn.net/u011488009/article/details/104608760
❝网上的说法是:因为主从日志版本号不一致而导致
分析过程:
- 之前在slave上看replica的状态发现,Source_Log_File参数中显示的Binlog的版本号是:mysql-bin.000053
- 在master上查看master的状态,发现主binlog(主日志)版本号是:mysql-bin.000059
mysql> show master status\G; *************************** 1. row *************************** File: mysql-bin.000059 Position: 5408067 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 9208096f-4731-11ec-a23e-005056210589:1-30, 92099aae-4731-11ec-a3da-00505629525b:1-953171 1 row in set (0.00 sec)
- 结合网上的参考资料,以及通过slave和master的binlog日志版本号的对比,发现确实是不一致,果不其然,看来网上的资料说的是对的。
三、尝试解决
- 在master上操作
# 刷新主日志,这时主服务器会重新创建一个binlog文件 mysql> flush logs; Query OK, 0 rows affected (0.02 sec) # 查看主日志的版本号和位置,这时的主日志版本是mysql-bin.000060,位置是4710 mysql> show master status\G; *************************** 1. row *************************** File: mysql-bin.000060 Position: 4710 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 9208096f-4731-11ec-a23e-005056210589:1-30, 92099aae-4731-11ec-a3da-00505629525b:1-953263 1 row in set (0.00 sec) ERROR: No query specified mysql>
- 在slave上操作
# 停止复制 mysql> stop replica; Query OK, 0 rows affected, 1 warning (0.00 sec) # 修改主日志的版本和位置信息,跟master保持一致 mysql> change master to master_log_file ='mysql-bin.000060',master_log_pos=4710; Query OK, 0 rows affected, 3 warnings (0.05 sec) # 刷新权限 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) # 启动复制 mysql> start replica; Query OK, 0 rows affected (0.01 sec) # 查看slave的状态,发现IO线程已经是YES,问题解决 mysql> show replica status\G; *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 192.168.11.152 Source_User: syn_b Source_Port: 3306 Connect_Retry: 60 Source_Log_File: mysql-bin.000060 Read_Source_Log_Pos: 200550 Relay_Log_File: zbx-db01-relay-bin.000002 Relay_Log_Pos: 324 Relay_Source_Log_File: mysql-bin.000060 Replica_IO_Running: Yes Replica_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Source_Log_Pos: 200550 Relay_Log_Space: 536 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Source_SSL_Allowed: No Source_SSL_CA_File: Source_SSL_CA_Path: Source_SSL_Cert: Source_SSL_Cipher: Source_SSL_Key: Seconds_Behind_Source: 0 Source_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Source_Server_Id: 6 Source_UUID: 9208096f-4731-11ec-a23e-005056210589 Source_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates Source_Retry_Count: 86400 Source_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Source_SSL_Crl: Source_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: 9208096f-4731-11ec-a23e-005056210589:1-23, 92099aae-4731-11ec-a3da-00505629525b:1-953551 Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Source_TLS_Version: Source_public_key_path: Get_Source_public_key: 0 Network_Namespace: 1 row in set (0.00 sec) ERROR: No query specified mysql>
❝关于刷新权限的命令:flush privileges,这条命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。