欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

the master‘s binary log is corrupted (you can check this by running ‘mysqlbinlog‘ on the binary log)

程序员文章站 2024-03-21 09:16:11
...

the master‘s binary log is corrupted (you can check this by running ‘mysqlbinlog‘ on the binary log)

一. 问题背景

搭建mysql主从复制:

  • 主机:在windows上,mysql版本5.7
  • 从机:在CentOS7上,mysql版本5.5

报错:Slave can not handle replication events with the checksum that master is configured to log;

解释: 一般出现在主机版本比从机版本高。由于5.7使用了crc32做binlog的checksum;
当一个event被写入binary log(二进制日志)的时候,checksum也同时写入binary log,然后在event通过网络传输到从服务器(slave)之后,再在从服务器中对其进行验证并写入从服务器的relay log.

二. 解决方案

  1. 关闭主机上的MySQL服务
  2. 打开主机上MySQL的my.ini文件,在[mysqld]下输入binlog_checksum =none,如下:the master‘s binary log is corrupted (you can check this by running ‘mysqlbinlog‘ on the binary log)
  3. 保存my.ini文件,启动主机上的mysql服务。
  4. 在从机上按ctrl+c关闭当前进程,然后输入service mysql restart;重启MySQL服务
  5. 重启完后,在从机上输入mysql -uroot -p123456(p后面为你的数据库密码,u后面为你的数据库用户名)
  6. 进入mysql后,先stop slave;
  7. 然后到主机那里flush logs;,再show master status;,查到如下:
    the master‘s binary log is corrupted (you can check this by running ‘mysqlbinlog‘ on the binary log)
  8. 在从机里面change master to master_log_file='上面图中第一个红色圈的值',master_log_pos=第二个红色圈的值;
  9. 在从机里面slave start;
  10. 在从机里面show slave status\G;,就可以看到如下:

the master‘s binary log is corrupted (you can check this by running ‘mysqlbinlog‘ on the binary log)

 

 

处理slave(低版本)复制master(高版本)产生的error 1236

 

背景知识:

mysql 5.6里加入了replication event checksum(主从复制事件校验)功能,此特性能较为容易的判断出是由何种原因导致的主从数据不一致。

处理过程:

// 因某些特别的需求,需要对一台mysql 5.6的master配置一个mysql 5.5的slave(不推荐)。

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status \G
*************************** 1. row ***************************
......
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
......           
        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.000990' at 661485030, the last event read from './mysql-bin.000990' at 661485030, the last byte read from './mysql-bin.000990' at 120.'
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
......

// 开启slave时报error 1236,处理方法:

# on Master:

mysql> show variables like 'binlog_checksum%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| binlog_checksum | CRC32 |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> set global binlog_checksum='NONE';
Query OK, 0 rows affected (0.22 sec)

mysql> show variables like 'binlog_checksum%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| binlog_checksum | NONE  |
+-----------------+-------+
1 row in set (0.00 sec)

注:在修改"bingo_checksum"后,如果原先在slave上使用的是mysqldump导出的数据副本进行的数据导入,那么需要使用mysqldump(需要得到master log pos,在slave上导出时使用'--dump-slave=2')重新生成一份 "bingo_checksum"修改后的sql文件去slave上进行数据导入。

 

相关标签: MYSQL主从