MySQL案例09:Last_IO_Error: Got fatal error 1236 from master when reading data from binary log
刚处理完“挖矿”事件,在做最后一个MySQL NBU备份的时候,发现从库有问题,好奇的是怎么主从状态异常没有告警呢?先不管这么多了,处理了这个问题再完善告警内容。
一、错误信息
从库show slave status \G看到的错误信息如下:
Slave_IO_Running: No
Slave_SQL_Running: Yes
Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the first event 'mysql-bin.000081' at 480141113, the last event read from './mysql-bin.000081' at 4, the last byte read from './mysql-bin.000081' at 4.'
二、错误原因
这里看到从库的io_thread已经终止,错误编号是1236,具体是由于读取主库的binlog日志位置(the first event 'mysql-bin.000081' at 480141113, the last event read from './mysql-bin.000081' at 4)不对导致主从失败建立失败。
三、解决方案
1.检查从库状态以及读取、执行的binlog信息
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: xx.xx.xx.xx
Master_User: username
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.
Read_Master_Log_Pos: 480141113
Relay_Log_File: mysql9017-relay-bin.000163
Relay_Log_Pos: 480141259
Relay_Master_Log_File: mysql-bin.000081
Slave_IO_Running: No
Slave_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_Master_Log_Pos: 480141113
Relay_Log_Space: 480141462
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: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the first event 'mysql-bin.000081' at 480141113, the last event read from './mysql-bin.000081' at 4, the last byte read from './mysql-bin.000081' at 4.'
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 17
1 row in set (0.00 sec)
2.查看主库的binlog内容
[backup]# mysqlbinlog mysql-bin.000081 >mysql-bin.log

看到主库binlog日志mysql-bin.000081最大的pos为480140557,但从库要读取的是'mysql-bin.000081' at 480141113,显然从库要读的pos值比主库本身存在的pos值大,导致读取不到,进而失败。
可通过下面语句查看binlog的pos信息和日志内容
mysql> show binlog events in 'mysql-bin.000081' from 480140557 limit 10;
Empty set (0.04 sec)
3.更改从库的同步位置,完成数据重新同步
主库:
mysqlbinlog mysql-bin.000082 |more
从库:
change master to master_host='xx.xx.xx.xx',master_user='username',master_port=3306,master_password='password',master_log_file='mysql-bin.000082',master_log_pos=4;
start slave;
show slave status \G
主从同步正常

4.主库参数改进
导致这个原因很大程度上是由于主从在同步的过程中,主库异常断电,导致内存数据传输到从库但没有提交到binlog日志,即主库 sync_binlog设置可能有问题,在主库检查参数设置:
mysql> show global variables like '%sync_binlog%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sync_binlog | 0 |
+---------------+-------+
1 row in set (0.00 sec)
果然其值是 0,不主动同步binlog cache的数据到磁盘,而依赖操作系统本身不定期把文件内容 flush 到磁盘。设为 1 最安全,在每个语句或事务后同步一次 binary log,即使在崩溃时也最多丢失一个语句或事务的日志,但因此也最慢。这里设置为0,断电的情况下导致binlog cache数据丢失没有写入主库的binlog,但binlog信息已同步至从库。这种情况容易导致主从数据不一致,所以即使恢复主从数据后,依旧要通过主从数据对比校验数据的一致性。
mysql> set global sync_binlog=1;
Query OK, 0 rows affected (0.00 sec)
更改配置文件my.cnf设置sync_binlog=1
5.主从数据校验
pt-table-checksum h=master_ipaddr,u=username,p='password',P=mysql_port --nocheck-binlog-format --recursion-method=hosts
pt-table-checksum h=master_ipaddr,u=username,p='password',P=mysql_port --nocheck-binlog-format --recursion-method=hosts
Checking if all tables can be checksummed ...
Starting checksum ...
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
08-03T17:49:29 0 0 595 1 0 0.186 user.hole
其中--recursion-method有几种方式查看从库信息,这里采用的是hosts方式,需要在从库加入如下参数,方可在主库执行show slave hosts查看从库的信息
report_host=slave_ip
report_port=slave_port
METHOD USES
=========== =============================================
processlist SHOW PROCESSLIST
hosts SHOW SLAVE HOSTS
cluster SHOW STATUS LIKE 'wsrep\_incoming\_addresses'
dsn=DSN DSNs from a table
none Do not find slaves
6.innodb_flush_log_at_trx_commit参数扩展
innodb_flush_log_at_trx_commit 参数指定了 InnoDB 在事务提交后的日志写入频率。这么说其实并不严谨,且看其不同取值的意义和表现。
当 innodb_flush_log_at_trx_commit 取值为 0 的时候,log buffer 会 每秒写入到日志文件并刷写(flush)到磁盘。但每次事务提交不会有任何影响,也就是 log buffer 的刷写操作和事务提交操作没有关系。在这种情况下,MySQL性能最好,但如果 mysqld 进程崩溃,通常会导致最后 1s 的日志丢失。
当取值为 1 时,每次事务提交时,log buffer 会被写入到日志文件并刷写到磁盘。这也是默认值。这是最安全的配置,但由于每次事务都需要进行磁盘I/O,所以也最慢。
当取值为 2 时,每次事务提交会写入日志文件,但并不会立即刷写到磁盘,日志文件会每秒刷写一次到磁盘。这时如果 mysqld 进程崩溃,由于日志已经写入到系统缓存,所以并不会丢失数据;在操作系统崩溃的情况下,通常会导致最后 1s 的日志丢失。
MySQL案例09:Last_IO_Error: Got fatal error 1236 from master when reading data from binary log的更多相关文章
- mysql从库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'报错处理
年后回来查看mysql运行状况与备份情况,登录mysql从库查看主从同步状态 mysql> show slave status\G; *************************** . ...
- 【MySQL】MySQL同步报错-> Last_IO_Error: Got fatal error 1236 from master when reading data from binary log
这个报错网上搜索了一下,大部分是由于MySQL意外关闭或强制重启造成的binlog文件事务点读取异常造成的主从同步报错 Last_IO_Error: Got fatal error 1236 from ...
- mysql 主从 Got fatal error 1236 from master when reading data from binary log: 'Could not find first 错误
本地MySQL环境,是两台MySQL做M-M复制.今天发现错误信息: mysql 5.5.28-log> show slave status\G ************************ ...
- Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary lo
mysql> show slave status\G *************************** 1. row *************************** ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
setup slave from backup i got error Got fatal error 1236 from master when reading data from binary l ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列一:
从库报这个错误:Got fatal error 1236 from master when reading data from binary log: 'Could not find first lo ...
- Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列三:重置主从同步
1:停止slave服务器的主从同步 stop slave; 2:对Master数据库加锁 flush tables with read lock; 3:备份Master上的数据 mysqldump - ...
- 主从同步遇到 Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'时怎么解决
首先遇到这个是因为binlog位置索引处的问题,不要reset slave: reset slave会将主从同步的文件以及位置恢复到初始状态,一开始没有数据还好,有数据的话,相当于重新开始同步,可能会 ...
- Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position
在source那边,执行: flush logs;show master status; 记下File, Position. 在target端,执行: CHANGE MASTER TO MASTER_ ...
随机推荐
- java学习-get和post请求
摘要 看完本文可以知道,使用java原生编写get/post请求的步骤,进行网络请求时应该注意的地方. 这里使用java自带的HttpUrlConnection对象进行网络请求, 请求步骤大致分为五步 ...
- MBIST:用于嵌入式存储器的可测试设计技术
MBist技术可以自动实现存储器单元或阵列的RTL级内建自测试电路,MBIST的EDA工具支持多种测试算法的自动实现,可针对一个或多个内嵌存储器自动创建BIST逻辑,并完成BIST逻辑与存储器的连接, ...
- [转]AngularJS中$timeout和$interval的用法详解
本文转自:http://www.cnblogs.com/moli-/p/5827618.html 1. 先将$interval,$timeout,作为参数注入到controller中,例如rds.co ...
- 使用Repeater控件实现三层嵌套以及分页效果
PS: 第一次用Repeater控件 记录一下 请忽略我的命名不规范 请忽略我的最终效果图(太丑了) 需要用到的朋友可以自行调整的漂亮点 ====================最终效果图===== ...
- Struts2和MVC的简单整合
1.首先还是创建一个简单Maven的项目,导入jar包, <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- [日常] PHP设置 include_path 配置选项
动态设置php.ini中的include_path 配置选项: 两种方式set_include_path($new_include_path)ini_set('include_path',$new_i ...
- 【原】Shiro框架基础搭建[2]
简介: 关于搭建一个最基础的shiro网上的例子有很多,这里是记录一下自己尝试去看官方文档所搭建的一个小demo,项目采用的是原始的java静态工程,导入相关jar包后就能运行. 首先进入官网http ...
- MySQL的数据控制语言DCL
我们使用DDL的"CREATE USER"语句创建用户,新的SQL用户不允许访问属于其他SQL用户的表,也不能立即创建自己的表,它必须被授权.可以授予的权限包括以下几组: 1.列权 ...
- 使用CSS3改变文本选中的默认颜色——张鑫旭
关于浏览器文字选中颜色 以我的系统举例(xp 默认主题),浏览器上页面文字选中后默认的背景色是一种蓝色, 不同浏览器的颜色有些许差异,但大致相同,文字颜色也近乎白色,如下图所示,截自Firefox3. ...
- Git 学习之git 分支(三)
Git 分支 几乎每一种版本控制系统都以某种形式支持分支.使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作.在很多版本控制系统中,这是个昂贵的过程,常常需要创建一个源代码目录的 ...