Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from position > file size', Error_code: 1236
MySQL主从复制报错,MySQL主主复制结构,MySQL版本5.7.32
2023-08-31T09:08:29.316553+08:00 1 [ERROR] Error reading packet from server for channel '': Client requested master to start replication from position > file size (server_errno=1236) 2023-08-31T09:08:29.316596+08:00 1 [ERROR] Slave I/O for channel '': Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from position > file size', Error_code: 1236
查看叶老师之前5.6的文章说是“主库确实没有设置为双1”造成的,如下
文章如下
1. 问题现象 版本:MySQL 5.6,采用传统 binlog file & pos 方式配置的主从复制结构。 实例重启后,主从复制报错如上图所示。 2. 错误含义 错误分为2部分。 第一部分 Client requested master to start replication from position > file size; 第一部分 这部分来源于主库的DUMP线程函数 mysql_binlog_send ->sender.run ->Binlog_sender::init ->Binlog_sender::check_start_file if((file= open_binlog_file(&cache, m_linfo.log_file_name, &errmsg)) < 0) { set_fatal_error(errmsg); return1; } size= my_b_filelength(&cache); end_io_cache(&cache); mysql_file_close(file, MYF(MY_WME)); if(m_start_pos > size) { set_fatal_error( "Client requested master to start replication from " "position > file size"); return1; } 关键就是m_start_pos和size两个值,其中m_start_pos来源于从库需要读取的位点。而size则是本binlog文件的大小,那么很容易理解如果io线程需要的pos点比本binlog文件的大小还要大,那么自然不对。 第二部分 这部分也来源于DUMP线程 mysql_binlog_send ->sender.run ->Binlog_sender::init -> while(!has_error && !m_thd->killed) #如果正常这里开始循环读取binlog event,如果前面出错则直接继续后面逻辑 #如果有读取错误则报错 my_snprintf(error_text, sizeof(error_text), "%s; the first event '%s' at %lld, " "the last event read from '%s' at %lld, " "the last byte read from '%s' at %lld.", m_errmsg, m_start_file, m_start_pos, m_last_file, m_last_pos, log_file, my_b_tell(&log_cache)); 这里我们主要看看m_start_pos和m_last_pos,实际上m_start_pos就是和前面报错一致的来自从库需要读取的位点信息,而m_last_pos来自dump线程,就是最后读取的位置,显然这里一次都没有读取,因此位置为最开始的pos 4。 3. 可能的原因 分析后觉得最有可能原因应该和sync_binlog 有关。 如果我们没有设置为1,那么可能os cache没有刷盘,如果主库服务器直接crash重启很容易就遇到这种问题。 稍微google查询了一下发现很大部分出现这种错误都是由于服务器crash且sync_binlog 没设置为 1导致的。 这也证明我们的说法。 最后查看问题数据库的主库确实没有设置为双1。 那么通过这个小案例,我们已经更加深刻体会到设置双1的重要性。
转自
MySQL 5.6 主从报错一例_start
https://www.sohu.com/a/455566083_610509
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2020-09-01 windows系统垃圾清理脚本【转】
2018-09-01 python的pymysql使用方法【转】
2017-09-01 java线上应用故障排查之二:高内存占用【转】
2017-09-01 Java线上应用故障排查之一:高CPU占用【转】
2017-09-01 JAVA 之 Tomcat知识框架【转】