1、修改MySQL配置: 主库配置 server-id = 3 binlog-do-db=xmcp_gxfc #the db need to sync binlog-ignore-db = mysql #不需要同步的数据库 binlog-ignore-db = redmine #不需要同步的数据库 log_slave_updates = 1 binlog_format=mixed relay_log = /usr/local/mysql/relay_log/mysql-relay-bin read_only = 1
2创建账号 grant replication slave on . to 'slave2'@'%' identified by 'FjAfj6#xajot#K%V';
grant replication slave on . to 'slave3'@'%' identified by 'FjAfj6#xajot#K%V';
更新数据库权限
mysql>flush privileges;
mysql> show master status;
记录下 File为mysql-bin.000001 记录下 position为 154
3、修改从库MySQL配置: 从库配置: server-id = 5 log-bin = mysql-bin replicate-do-db=xmcp_gxfc binlog_format=mixed relay_log=/usr/local/mysql/relay_log/mysql-relay-bin read_only = 1
4、执行同步命令
执行同步命令,设置主数据库ip,同步帐号密码,同步位置
mysql>change master to master_host='10.2.2.2',master_user='slave2',master_password='FjAfj6#xajot#K%V',master_log_file='mysql-bin.000001',master_log_pos=154;
开启同步功能
mysql>start slave;
5、检查从数据库状态: mysql> show slave statusG;
注:Slave_IO_Running及Slave_SQL_Running进程必须正常运行,即YES状态,否则说明同步失败。可用这两项判断从服务器是否挂掉
mysql > SET GLOBAL server_id=2;
6、Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
原因分析:
mysql 5.6的复制引入了uuid的概念,各个复制结构中的server_uuid得保证不一样,但是查看到直接copy data文件夹后server_uuid是相同的,show variables like '%server_uuid%';
解决方法:
找到data文件夹下的auto.cnf文件,修改里面的uuid值,保证各个db的uuid不一样,重启db即可
场景二:创建主从关系时copy了同样的my.cnf文件,报错
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids;
原因分析:
和server_uuid类似,servier_id也得保证不一样
解决方法:
找到my.cnf配置文件中的server_id,修改从库的server_id保证和复制结构中的其他db不一样,重启db即可