mysql多源复制安装
多源复制的意思是多主一从。
多源复制的前提是必须要开启GTID模式。
master1 :192.168.1.110
master2 :192.168.1.111
slave :192.168.1.150
1、同步数据:
master1:
mysqldump -uroot -p123456 --master-data=2 --single-transaction -B game > game.sql
master2:
mysqldump -uroot -p123456 --master-data=2 --single-transaction -B game > game.sql
将数据移动到slave从机上。
在slave上导入两个数据。
查找并记录此时的positon。
2、建立复制账号:
master1:
grant replication slave on *.* to 'backup'@'192.168.%' identified by '123456';
master2:
grant replication slave on *.* to 'backup'@'192.168.%' identified by '123456';
slave:
grant replication slave on *.* to 'backup'@'192.168.%' identified by '123456';
3、修改配置文件my.cnf:
添加:
master_info_repository=TABLE relay_log_info_repository=TABLE
4、在slave上操作(定位至master机器上):
定位到master1上:
CHANGE MASTER TO MASTER_HOST='192.168.1.110',MASTER_USER='backup', MASTER_PASSWORD='123456',MASTER_LOG_FILE='Master_1-bin.000012',MASTER_LOG_POS=15013 FOR CHANNEL 'master_1';
定位到master2上:
CHANGE MASTER TO MASTER_HOST='192.168.1.111',MASTER_USER='backup', MASTER_PASSWORD='123456',MASTER_LOG_FILE='Master_1-bin.000019',MASTER_LOG_POS=323 FOR CHANNEL 'master_2';
5、启动多源复制:
start slave;