实验环境:

192.168.132.121   master1

192.168.132.122   master2

192.168.132.123   slave

使用gtid的方式

两个主分别是192.168.132.121和192.168.132.122,一个从端192.168.132.123分别从两个主端同步数据

192.168.132.121 master1配置

[root@master ~]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid

[root@master ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* to 'replication'@'192.168.132.122' identified by '';
mysql> grant replication slave on *.* to 'replication'@'192.168.132.123' identified by '';

192.168.132.122 master2配置

[root@master2 ~]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid [root@master2 ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* to 'replication'@'192.168.132.121' identified by '';
mysql> grant replication slave on *.* to 'replication'@'192.168.132.123' identified by '';

192.168.132.123 slave配置

[root@slave ~]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
[root@slave ~]# mysql -uroot -p123456

配置从库

mysql> change master to master_host='192.168.132.121',master_user='replication',master_port=,master_password='',master_auto_position= for channel 'master-1';
ERROR (HY000): To have multiple channels, repository cannot be of type FILE; Please check the repository configuration and convert them to TABLE.
mysql> show variables like '%repository%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | FILE |
| relay_log_info_repository | FILE |
+---------------------------+-------+

需要设置convert表

/etc/my.cnf
[mysqld] #添加
master_info_repository=TABLE
relay_log_info_repository=TABLE

[root@slave ~]# systemctl restart mysqld

[root@slave ~]# mysql -uroot -p123456

mysql> show variables like '%repository%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | TABLE |
| relay_log_info_repository | TABLE |
+---------------------------+-------+
mysql> change master to master_host='192.168.132.121',master_user='replication',master_port=,master_password='',master_auto_position= for channel 'master-1';
mysql> change master to master_host='192.168.132.122',master_user='replication',master_port=,master_password='',master_auto_position= for channel 'master-2';

查看从端状态

mysql> start slave;
Query OK, rows affected (0.01 sec) mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.121
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log-master@002d1.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 63a7f26f-a196-11e9-a2b2-000c2991dd19
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 63a7f26f-a196-11e9-a2b2-000c2991dd19:-
Executed_Gtid_Set: 5ad46c94-a197-11e9--000c29f004c9:,
63a7f26f-a196-11e9-a2b2-000c2991dd19:-,
662134df-a196-11e9-b432-000c2963fd11:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name: master-1 #通道1,连接master1
Master_TLS_Version:
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.122
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log-master@002d2.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 662134df-a196-11e9-b432-000c2963fd11
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 662134df-a196-11e9-b432-000c2963fd11:-
Executed_Gtid_Set: 5ad46c94-a197-11e9--000c29f004c9:,
63a7f26f-a196-11e9-a2b2-000c2991dd19:-,
662134df-a196-11e9-b432-000c2963fd11:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name: master-2 #通道2,连接master2
Master_TLS_Version:

查看进程

mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| | root | localhost | NULL | Query | | starting | show processlist |
| | system user | | NULL | Connect | | Waiting for master to send event | NULL |
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL |
| | system user | | NULL | Connect | | Waiting for master to send event | NULL |
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+

验证

master1
mysql> create database master1;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| master1 |
| mysql |
| performance_schema |
| sys |
+--------------------+
master2
mysql> create database master2;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| master2 |
| mysql |
| performance_schema |
| sys |
+--------------------+
slave查看 #已经同步
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| master1 |
| master2 |
| mysql |
| performance_schema |
| sys |
+--------------------+

多源复制,配置完成

mysql主从之多元复制的更多相关文章

  1. 高性能Mysql主从架构的复制原理及配置详解

    温习<高性能MySQL>的复制篇. 1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台 ...

  2. Mysql主从同步(复制)

    目录: mysql主从同步定义      主从同步机制 配置主从同步      配置主服务器      配置从服务器 使用主从同步来备份      使用mysqldump来备份      备份原始文件 ...

  3. 转:高性能Mysql主从架构的复制原理及配置详解

    温习<高性能MySQL>的复制篇. 1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台 ...

  4. 高性能Mysql主从架构的复制原理及配置详解(转)

    温习<高性能MySQL>的复制篇. 1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台 ...

  5. Mysql主从同步(复制)(转)

    文章转自:https://www.cnblogs.com/kylinlin/p/5258719.html 目录: mysql主从同步定义 主从同步机制 配置主从同步 配置主服务器 配置从服务器 使用主 ...

  6. 高性能Mysql主从架构的复制原理及配置

    1. 复制概述 1.1 mysql支持的复制类型 1.2 复制解决的问题 1.3 复制如何工作 2. 2 复制配置 2.1创建复制帐号 2.2拷贝数据 2.3配置master 2.4配置slave 2 ...

  7. MySQL主从双向同步复制

    本文介绍了mysql主从,实现mysql的双向同步复制. MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日 ...

  8. Mysql学习总结(18)——Mysql主从架构的复制原理及配置详解

    一.复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...

  9. Mysql主从架构的复制

    复制类型 (1)基于语句的复制:  在主服务器上执行的SQL语句,在从服务器上执行同样的语句.MySQL默认采用基于语句的复制,效率比较高.  一旦发现没法精确复制时,会自动选着基于行的复制. (2) ...

随机推荐

  1. js this详解

    This的定义: 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用. this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是 ...

  2. Libev源码分析02:Libev中的IO监视器

    一:代码流程 在Libev中,启动一个IO监视器,等待该监视器上的事件触发,然后调用该监视器的回调函数.整个的流程是这样的: 首先调用ev_default_loop初始化struct  ev_loop ...

  3. poj 1271 && uva 10117 Nice Milk (半平面交)

    uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...

  4. CodeForces 825G"Tree Queries"(选根建树)

    传送门 •参考资料 [1]:CodeForces 825G Educational Round #25 G :建树选根大法+O1大法+iostream解绑了还是慢 •题意 给定一颗包含 n 个节点的树 ...

  5. java Math和Random和UUID

    Math类 public final class Math extends Object 以下X表示double,float,int, long abs(X x):求绝对值 max(X x1,X x2 ...

  6. [转]基于VS Code快速搭建Java项目

    有时候随手想写一点Java测试代码,以控制台程序为主,还会用到一些其它框架,并基于Maven构建. 1.Java Extension Pack一定要安装. 2.VS Code打开一个指定目录,创建相应 ...

  7. 浅谈集合框架二 List、Set常用方法

    最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出.初学者对于本篇博客只建议作为参考,欢迎留言共同学习. 之前有介绍集合框架的体系 ...

  8. python基础三之字符串

    Python的数据类型 数字(int),如1,2,3,用于计算. 字符串(str),如s = 'zxc',储存少量数据,进行操作. 布尔值(bool),True和False,用于进行判断. 列表(li ...

  9. JS开发常用工具函数 总结

    js原生工具库 1.isStatic:检测数据是不是除了symbol外的原始数据 */ function isStatic(value) { return( typeof value === 'str ...

  10. linux poll 和 select

    使用非阻塞 I/O 的应用程序常常使用 poll, select, 和 epoll 系统调用. poll, select 和 epoll 本质上有相同的功能: 每个允许一个进程来决定它是否可读或者写一 ...