美文网首页
mysql主从配置遇到的坑

mysql主从配置遇到的坑

作者: 東_b3af | 来源:发表于2020-12-21 14:21 被阅读0次

首先在这两台服务器安装mysql数据库,安装方法参考《离线安装mysql数据库》

(1)、配置主库

修改my.cnf文件,在[mysqld]加入下面的内容:

# 服务的唯一编号server-id=1# 开启mysql binlog功能log-bin= mysql-bin# binlog记录内容的方式,记录被操作的每一行binlog_format= ROW# 减少记录日志的内容,只记录受影响的列binlog_row_image= minimal# 指定需要复制的数据库名为jgywbinlog-do-db= jgyw

修改好配置文件,重启mysql服务

servicemysqld restart

创建从库同步数据的账号

grantreplicationslaveon*.*to'jgyw'@'192.168.197.136'identifiedby'jgyw@123';flushprivileges;

注意:上面这两个命令是在mysql的终端执行的。

查看主库的状态:

mysql的终端执行:

showmasterstatus\G;

返回的信息为:

*************************** 1. row***************************

            File: mysql-bin.000002

        Position: 2380

    Binlog_Do_DB: jgyw

Binlog_Ignore_DB:

Executed_Gtid_Set:

1 row in set (0.00 sec)

(2)、配置从库

修改my.cnf文件,在[mysqld]加入下面的内容:

# 服务的唯一编号server-id=2# 开启mysql binlog功能log-bin= mysql-bin# binlog记录内容的方式,记录被操作的每一行binlog_format= ROW# 减少记录日志的内容,只记录受影响的列binlog_row_image= minimal# 指定需要复制的数据库名为jgywreplicate-do-db= jgyw

修改好配置文件,重启mysql服务

servicemysqld restart

执行同步命令

mysql的终端执行:

# 设置主服务器ip,同步账号密码,同步位置changemastertomaster_host='192.168.197.135',master_user='jgyw',master_password='jgyw@123',master_log_file='mysql-bin.000002',master_log_pos=2380;# 开启同步功能startslave;

查看从库的状态

mysql的终端执行:

showslavestatus\G;

注意:Slave_IO_Running和Slave_SQL_Running的状态都为Yes时,说明从库配置成功

我配置之后,Slave_IO_Running 始终都是no  同步复制报Slave can not handle replication events with the checksum that master 错误

查了半天发现原来是两个数据库版本的问题 ,一个是mysql5.5 一个是mysql6.6

一:在master1做slave,master2做主数据库时成功。

二:在master1做master,master2做从数据库时报错

      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 5115510, the last event read from './mysql-bin.000001' at 5115510, the last byte read from './mysql-bin.000001' at 120.'

查询资料发现mysql版本为5.6时,

这个错误一般出现在master5.6,slave在低版本的情况下。这是由于5.6使用了crc32做binlog的checksum;

当一个event被写入binary log(二进制日志)的时候,checksum也同时写入binary log,然后在event通过网络传输到从(slave)之后,再在从服务器中对其进行验证并写入从服务器的relay log.

由于每一步都记录了event和checksum,所以我们可以很快地找出问题所在。

在master1中设置binlog_checksum =none;

重启mysql

重新查询master状态,show master status\G;

记录下来。

从服务器重新进行连接:

change master to master_host='192.168.15.201',master_user='repl',master_password='epimap.123456',master_log_file='mysql-bin.000012',master_log_pos=211;

即可解决5.5/5.6主主同步问题。

相关文章

网友评论

      本文标题:mysql主从配置遇到的坑

      本文链接:https://www.haomeiwen.com/subject/dyprnktx.html