error 1236 from master when reading data from binary log: ‘Slave can not handle replication events with the checksum that master is configured to log
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: mysql.%,test.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 451
Relay_Log_Space: 302
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: ‘Slave can not handle replication events with the checksum that master is configured to log;
the first event ‘mysql-bin.000001’ at 451, the last event read from ‘./mysql-bin.000001’ at 451, the last byte read from ‘./mysql-bin.000001′ at 120.’
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
show slave status \G;
环境:
centos 6.5
主—主–从–从–从(本环境)
也适用:
主—–从—-从—-从
主库: 5.6.25
从库:5.5.32
解决:
主库添加:
vim /etc/my.cnf
binlog_checksum=none
主库 重新 show master status \G
记录下来
mysql-bin.000002 | 439
从库
change master to master_host=’192.168.199.40′,master_port=3306,master_user=’slave’,master_password=’123456′,master_log_file=’mysql-bin.000002′,master_log_pos=439;
启动从库
start slave
show slave status \G
Slave_IO_Running: Yes (主库推送binlog线程) 必须yes,不然没法交互,他们要通信的。
Slave_SQL_Running: Yes(从库重放线程)必须yes,不然没法复制
问题解决。
原因:
主库用的 mysql5.6 , binlog_checksum 默认设置的是 crc32。新手建议,多看my.cnf,务必精通。就像开发的API那样。你懂的!
赠送:
目录[-]
网站有一个后台业务,叫searchEngine项目,基于Lucene 构建。主要提供索引构建和检索的功能,搜索引擎查询mysql 数据库然后根据数据状态来构建索引,这里采用的是 程序每隔一段时间主动轮询 mysql 查询 数据列 增删改的状态,对应的去增删改 Lucene 索引,然后会将索引的状态更新到数据列中,方便轮询的时候区分哪些是未索引的数据。
由于mysql主要采用myisam引擎,导致java程序构建索引 轮询数据库的时候,频繁锁表,页面查询的时候无法响应。这里做了下 mysql 主从同步,将所有业务上的更新和查找在 master 上进行,而Lucene后台服务操作slave库,同时也起到备份的作用。这里整理下做主从备份的一些配置。
主库 master:192.168.0.102,mysql 5.6.12,centos
从库 slave:192.168.0.100,mysql 5.5.13,centos
都是采用源码编译,安装过程可以查看我的这篇博文。master、slave 所有的数据表结构都一致。之前我做了一个双master 的配置,可以查看这里
1. master 配置
这里的配置只截取了部分 同步需要的配置,其他的优化方面的暂不考虑
my.cnf:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [client] port=3306 [mysqld] socket= /usr/local/mysql/mysql .sock basedir= /usr/local/mysql datadir= /usr/local/mysql/data log-error= /usr/local/mysql/data/mysql_error .log pid- file = /usr/local/mysql/data/mysql .pid log-bin = /usr/local/mysql/mysql-bin .log #二进制文件必须开启 explicit_defaults_for_timestamp= true innodb_flush_log_at_trx_commit=2 #日志flush到磁盘的,2表示写入到缓存,提高性能,操作系统崩溃会丢失部分数据 #master server_id=1 expire_logs_days = 10 max_binlog_size = 1G binlog- do -db = webportal #同步数据库 binlog-ignore-db=information_schema binlog-ignore-db=performance_schema binlog-ignore-db=mysql binlog-ignore-db= test |
创建同步用户,在主服务器上为从服务器建立一个连接帐户,该帐户必须授予REPLICAITON SLAVE权限。在主服务器登陆mysql上执行
1 | grant replication slave on *.* to 'replication' @ '192.168.0.100' identified by '123456' ; |
注: replication@192.168.0.100这里是客户端的ip 可以使用 % 代替,表示允许任意的客户端,例如:
192.168.0.% 。表示该段地址的主机都可作为客户端。
查看master 状态:
1 2 3 4 5 6 7 8 | mysql> show master status\G; *************************** 1. row *************************** File: mysql-bin.000001 Position: 416 Binlog_Do_DB: webportal Binlog_Ignore_DB: information_schema,performance_schema,mysql, test Executed_Gtid_Set: 1 row in set (0.00 sec) |
注意上面的 File 和 Position :slave 配置的时候会使用。
2. slave配置
1 2 3 4 | [mysqld] server_id=2 log-bin=mysql-bin.log replicate- do -db=webportal |
用change master语句指定同步位置
?
1 2 3 | mysql>change master to master_host= '192.168.0.102' , master_user= 'replication' , master_password= '123456' , master_log_file= 'mysql-bin.000001' , master_log_pos=525; 注:master_log_file,master_log_pos由上面master查出的状态值中确定。master_log_file对应File,master_log_pos对应Position。 |
启用slave;
?
1 | start slave; |
关闭slave;
1 | stop slave; |
查看状态:
1 | show slave status; |
这里出现了这样一个错误:
Last_IO_Error: Got fatal error 1236 from master when reading data from >> binary log: 'Slave can not handle replication events with the checksum that >> master is configured to log; the first event 'mysql-bin.000001'
这是由于 master 用的 mysql5.6 , binlog_checksum 默认设置的是 crc32。 如果slave用的 5.5 或者更早的版本,请将master的 binglog_checksum设置为 none。
binlog_checksum=none
重启master : ./mysqld restart
查看slave :show slave status\G;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | mysql> show slave status\G; *************************** 1. row *********** Slave_IO_State: Waiting for mas Master_Host: 192.168.0.102 Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.00000 Read_Master_Log_Pos: 120 Relay_Log_File: YZ-relay-bin.00 Relay_Log_Pos: 266 Relay_Master_Log_File: mysql-bin.00000 Slave_IO_Running: Yes #必须为yes Slave_SQL_Running: Yes #必须为yes Replicate_Do_DB: webportal 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: 120 Relay_Log_Space: 419 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: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec) |
注:Slave_IO及Slave_SQL进程必须正常运行,即YES状态,否则都是错误的状态(如:其中一个NO均属错误)。
参考:
http://my.oschina.net/congqian/blog/138485
赠送2
MySQL 搭建主从同步,从报 Slave can not handle replication events with the checksum that master 错误问题
心血来朝,想复习一下MySQL主从搭建,虽开打VM,分别开启了我以前安装的两台虚拟机,一台CentOS6 一台Ubuntu,这两台都安装好了MySQL数据库,安装啥的不说了,配置也没问题。但是但我把主上的数据库dump出来,复制来从上,然后做同步的时候报错了:
1 2 3 4 | Slave_IO_Running: No Slave_SQL_Running: Yes Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Slave can not handle replication events with the checksum that master is configured to log; the first event ' binlog.000005 ' at 805, the last event read from ' /data/dbdata/mysqllog/binlog/binlog .000005 ' at 805, the last byte read from ' /data/dbdata/mysqllog/binlog/binlog .000005 ' at 120.' |
百思不得奇解,还叫过DBA把我从做了一遍,还是报这个错,虽放 Google 一搜索,好家伙。
这是由于 master 用的 mysql5.6 , binlog_checksum 默认设置的是 crc32。 如果slave用的 5.5 或者更早的版本,请将master的 binglog_checksum设置为 none。
才记起来我 CentOS6 安装的是 mysql 5.6 版本, Ubuntu系统上安装的是 5.5版本
1 2 3 4 5 6 7 | root@mysql 19:22> select @@version; +------------+ | @@version | +------------+ | 5.6.16-log | +------------+ 1 row in set (0.00 sec) |
1 2 3 4 5 6 7 | root@(none) 19:36> select @@version; +------------+ | @@version | +------------+ | 5.5.27-log | +------------+ 1 row in set (0.00 sec) |
解决步骤:
- 关闭 master checksum:
1 2 3 | set global binlog_checksum= 'NONE' ; show variables like '%checksum%' ; |
- 添加 my.cnf 配置文件中添加如下设置,下次重启就可以不用做步骤1,直接生效了。
1 | binlog_checksum=NONE |
- 重新查询master状态:
1 | show master status\G; |
搞定。
然后我叫DAB也要把这问题好好记一下,没准下次就会遇到了。
binlog checksum功能介绍
http://blog.sina.com.cn/s/blog_53fab15a0102vodv.html
参考:
https://www.liurongxing.com/mysql-slave-can-not-handle-replication-events-with-the-checksum-that-master.html
后来发现是因为主库MySQL版本是5.6, 从库是5.5
5.6的版本中加入了replication event checksum,主从复制时间校验功能,所以需要把这个关掉才能正常同步到5.5的slave
修改主库 /etc/my.cnf
增加下一行
binlog_checksum=none
重启mysql
现在再看从库status就正常了~