[mysqld] server-id = 1 log-bin=mysql1-bin #salve-net-timeout默认是3600秒,缩短期是为了防止双YES的假象 slave-net-timeout=60 auto_increment_offset=2 auto_increment_increment=2 若是要指定同步或不一样步哪些库,可以使用以下参数 #binlog-do-db=osyunweidb #须要同步的数据库名,若是有多个数据库,可重复此参数,每一个数据库一行 #binlog-ignore-db=mysql #不一样步mysql系统数据库
[mysqld] server-id = 2 log-bin=mysql2-bin #salve-net-timeout默认是3600秒,缩短期是为了防止双YES的假象 slave-net-timeout=60 auto_increment_offset=1 auto_increment_increment=2
多主和主从有一点区别:由于在多主中都有对服务器有写的权限,因此会形成主键冲突。从而致使同步失败。因此须要保证自增加的数据不一样。使用auto_increment_offset
和auto_increment_increment
来解决。mysql
auto_increment_offset auto_increment_increment
这两个参数的做用:sql
auto_increment_increment:自增值的自增量数据库
auto_increment_offset: 自增值的偏移量服务器
通常设置:网络
auto_increment_offset=1 偏移量从开始,依次增长ide
auto_increment_offset=N 有几台主服务器,就设置为N,这样就能够保证他们之间的主键不冲突。日志
在主库上锁表 flush tables with read lockcode
在从库上执行:server
stop slave; #跳过错误的步骤,能够改变后面的数字,实现屡次跳转 set global sql_slave_skip_counter =1; start slave; show slave status\G; 解锁表 unlock tables;
2.重作,实现彻底同步。适用于要求数据彻底统一的状况下:ip
1. 在主库上锁表 2.进行主库数据备份 3.查看master的状态 4.将备份文件拷贝到从库 ###################### 5.中止从库的状态 6.导入备份的数据库 7.设置主从同步 8.开启从同步 9.查看同步的状态 10.在master上解锁
配置:
master1 mysql:5.6 master2 mysql: 5.5
在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,因此看报错就知道是没法checksum。
解决: 在master1配置文件中设置binlog_checksum =none
;重启,而后从新进行链接就行了。