MySQL安装我就不多说了,直接介绍配置方法。
以Linux为例:
master: 192.168.0.10 简称为A
slave: 192.168.0.11 简称为B
1. 修改A的/etc/mysql/my.cnf文件
[mysqld] server-id = 129 #唯一值 log_bin = /var/log/mysql/mysql-bin.log #二进制方式保存日志
2. 修改A的/etc/mysql/my.cnf文件
[mysqld] server-id = 130 #唯一值 log_bin = /var/log/mysql/mysql-bin.log #二进制方式保存日志
3. 在A创建一个专门用做主从的用户,尽量不要使用root
grant replication slave,reload,super on *.* to 'slaveuser'@'%' indentified by '123456';
4. 在A执行以下命令:
show master status;

5. 在B设置master
change master to master_host='192.168.0.10', master_user='slaveuser', master_password='123456', master_log_file='bin-log.000001', master_log_pos=120;
参数说明:
master_host: MASTER的IP
master_user: 在第3步创建的用户名
master_password: 在第3步创建的用户名的密码
master_log_file:在第4步执行命令的结果中的File字段的值
master_log_pos:在第4步执行命令的结果中的Position字段的值。
6. 在B执行命令
1 start slave 2 show slave status;

如果Slave_IO_Running: Yes和Slave_SQL_Running: Yes,说明slave状态正常了。
在配置过程中,我遇到了一个问题。MASTER为Mysql的版本是5.6,SLAVE的Mysql的版本是5.5,导致出现下面的异常:
1 150304 14:17:11 [ERROR] Slave I/O: 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 'bin-log.000001' at 120, the last event read from 'D:\log\mysql\bin-log.000002' at 120, the last byte read from 'D:\log\mysql\bin-log.000002' at 120.', Error_code: 1236 2 150304 14:17:11 [Note] Slave I/O thread exiting, read up to log 'bin-log.000001', position 120
导致这个问题的原因是因为Mysql5.6版本使用CRC32作为binlog的checksum,可以在A的my.cnf中[mysqld]下面加入binlog-checksum = none就好了。
浙公网安备 33010602011771号