mysql5.7新特性多源复制很实用,方便对分库环境进行汇总,集中备份和数据统计分析。
我的实验环境3台机器,mysql版本:5.7.16
10.10.203.102 从库
10.10.203.93 主库
10.10.203.94 主库
操作步骤:
(1)当一个从库是多源复制结构,那么master_info和relay_log_info不能用file方式来存储,必须使用table,它不支持file。
10.10.203.102 从库上操作
在配置文件中新增:
[mysqld]
master_info_repository=TABLE
relay_log_info_repository=TABLE
在线动态修改:
STOP SLAVE;
SET GLOBAL master_info_repository = ‘TABLE‘;
SET GLOBAL relay_log_info_repository = ‘TABLE‘;
10.10.203.93 和 10.10.203.94 主库上操作【复制采用的传统方式,非GTID】
授权复制账号
mysql>grant replication slave,replication client on *.* to pgm@‘%‘ identified by ‘pgmfetion‘;
10.10.203.93上操作,记录file name和pos
/usr/local/mysql/bin/mysqldump -S /data/mysql/mysql9000/sock/mysql9000.sock -B kenney93 -R --single-transaction --master-data=2 >/tmp/kenney93.sql
[root@eut_config ~]# grep ‘CHANGE MASTER‘ /tmp/kenney93.sql
-- CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000004‘, MASTER_LOG_POS=2048;
10.10.203.94上操作,记录file name和pos
/usr/local/mysql/bin/mysqldump -S /data/mysql/mysql9000/sock/mysql9000.sock -B kenney94 -R --single-transaction --master-data=2 >/tmp/kenney94.sql
[root@localhost ~]# grep ‘CHANGE MASTER‘ /tmp/kenney94.sql
-- CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000002‘, MASTER_LOG_POS=1533;
10.10.203.102上导入备份93,94的备份
[root@localhost ~]# /usr/local/mysql/bin/mysql -S /data/mysql/mysql9000/sock/mysql9000.sock </tmp/kenney94.sql
[root@localhost ~]# /usr/local/mysql/bin/mysql -S /data/mysql/mysql9000/sock/mysql9000.sock </tmp/kenney93.sql
上边执行完之后,start slave;查看主从状态
(2)测试主从
10.10.203.93 主库
10.10.203.94 主库
10.10.203.102 从库
(3)通过performance_schema监控主从状态
(4)备注
4.1 多源复制中GTID和传统复制的操作命令
GTID方式的配置:
CHANGE MASTER TO MASTER_HOST=‘master1‘, MASTER_USER=‘rpl‘, MASTER_PORT=3451, MASTER_PASSWORD=‘‘, \
MASTER_AUTO_POSITION = 1 FOR CHANNEL ‘master-1‘;
传统方式的配置:
CHANGE MASTER TO MASTER_HOST=‘master1‘, MASTER_USER=‘rpl‘, MASTER_PORT=3451, MASTER_PASSWORD=‘‘ \
MASTER_LOG_FILE=‘master1-bin.000006‘, MASTER_LOG_POS=628 FOR CHANNEL ‘master-1‘;
4.2 启停方法
启动所有渠道的线程
START/STOP SLAVE thread_types
启动指定渠道的线程
START/STOP SLAVE thread_types FOR CHANNEL channel;
4.3 重置配置信息
重置所有渠道配置
RESET SLAVE;
重置指定渠道配置
RESET SLAVE FOR CHANNEL channel;
本文出自 “南山深处” 博客,请务必保留此出处http://kenneyzhou.blog.51cto.com/12427643/1885899
原文地址:http://kenneyzhou.blog.51cto.com/12427643/1885899