mysql 5.7 多源复制 原创

my.cnf要加两个参数才可以在GTID多源复制
master-info-repository=TABLE
relay-log-info-repository=TABLE
server1 连到 slave1 

mysql> change master to master_host=‘10.24.220.70‘,master_user=‘repl‘,master_password=‘123‘,master_port=3306,master_auto_position=1 for channel ‘slave1‘;
server1 连到 slave2 

mysql> change master to master_host=‘10.169.214.33‘,master_user=‘repl‘,master_password=‘123‘,master_port=3307,master_auto_position=1 for channel ‘slave2‘;
server1:mysql> start slave;    //两个通道一起起动了
Query OK, 0 rows affected (0.02 sec)

mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time | State                                                  | Info             |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
|  2 | root        | localhost | NULL | Query   |    0 | starting                                               | show processlist |
|  8 | system user |           | NULL | Connect |    3 | Waiting for master to send event                       | NULL             |
|  9 | system user |           | NULL | Connect |    3 | Slave has read all relay log; waiting for more updates | NULL             |
| 10 | system user |           | NULL | Connect |    3 | Connecting to master                                   | NULL             |
| 11 | system user |           | NULL | Connect |    3 | Slave has read all relay log; waiting for more updates | NULL             |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
5 rows in set (0.00 sec)
mysql> show slave status\G   //两个通道一起起动
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.24.220.70
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-slave1.000002
                Relay_Log_Pos: 355
        Relay_Master_Log_File: log.000001
             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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 563
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 101
                  Master_UUID: 1915a42e-ffa2-11e5-a6ca-00163e000601
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave1
           Master_TLS_Version:
*************************** 2. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 10.169.214.33
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: relay-log-slave2.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: Connecting
            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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 154
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master ‘[email protected]:3307‘ - retry-time: 60  retries: 3
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID:
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 160517 12:37:11
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave2
           Master_TLS_Version:
2 rows in set (0.00 sec)
mysql> stop slave;   //两个通道同时停止
Query OK, 0 rows affected (0.03 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.24.220.70
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-slave1.000002
                Relay_Log_Pos: 355
        Relay_Master_Log_File: log.000001
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 563
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 101
                  Master_UUID: 1915a42e-ffa2-11e5-a6ca-00163e000601
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave1
           Master_TLS_Version:
*************************** 2. row ***************************
               Slave_IO_State:
                  Master_Host: 10.169.214.33
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: relay-log-slave2.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 154
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master ‘[email protected]:3307‘ - retry-time: 60  retries: 4
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID:
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 160517 12:38:11
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave2
           Master_TLS_Version:
2 rows in set (0.00 sec)
mysql> start slave for channel ‘slave1‘;  // 停止单一通道
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.24.220.70
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-slave1.000003
                Relay_Log_Pos: 355
        Relay_Master_Log_File: log.000001
             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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 764
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 101
                  Master_UUID: 1915a42e-ffa2-11e5-a6ca-00163e000601
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave1
           Master_TLS_Version:
*************************** 2. row ***************************
               Slave_IO_State:
                  Master_Host: 10.169.214.33
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: relay-log-slave2.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 154
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master ‘[email protected]:3307‘ - retry-time: 60  retries: 4
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID:
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 160517 12:38:11
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave2
           Master_TLS_Version:
2 rows in set (0.00 sec)
mysql> show slave status for channel ‘slave1‘\G    //显示指定的通道状态
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.24.220.70
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-slave1.000003
                Relay_Log_Pos: 355
        Relay_Master_Log_File: log.000001
             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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 764
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 101
                  Master_UUID: 1915a42e-ffa2-11e5-a6ca-00163e000601
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave1
           Master_TLS_Version:
1 row in set (0.00 sec)
mysql> stop slave io_thread  for channel ‘slave1‘;        //停止批定通道的IO_THREAD
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status for channel ‘slave1‘\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.24.220.70
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-slave1.000003
                Relay_Log_Pos: 355
        Relay_Master_Log_File: log.000001
             Slave_IO_Running: No
            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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 764
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 101
                  Master_UUID: 1915a42e-ffa2-11e5-a6ca-00163e000601
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: slave1
           Master_TLS_Version:
1 row in set (0.00 sec)
时间: 2024-07-31 08:20:04

mysql 5.7 多源复制 原创的相关文章

mysql 5.7多源复制(用于生产库多主库合并到一个查询从库)

目前我们使用的是主从+分库分表的系统架构,主库有N个分库,从库为多个slave做负载均衡,所以数据库端的架构是下面这样的: 这就涉及到多个主库数据同步到不分库分表的从库共查询和管理类系统使用.在mysql 5.6以及之前的版本中,没有原生的解决方法,除非使用mariadb分支,在mysql 5.7之后支持多源复制,除了使用原生的多源复制之外,还有一个选择,就是使用案例开源的otter/canal.如果只是N个库合并到一个库的,我们使用mysql原生的复制,因为无论从稳定性还是运维成本.系统要求的

Mysql 5.7多源复制及并行复制功能

准备环境: os version:CentOS release 6.5 (Final) 服务器信息: Master1:192.168.1.29 Master2:192.168.1.37 Slave:192.168.1.86 1,修改my.cnf Slave中的my.cnf加入以下参数 启用enhanced multi-threaded slave (多线程复制) slave-parallel-type=LOGICAL_CLOCK slave-parallel-workers=8 master_i

MySQL 5.7.9多源复制报错修复

版本:5.7.9 用5.7.9的版本搭建MySQL多源复制测试环境 开发说复制出现问题,上去看了一下: mysql> show slave status\G*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 182.2.2.11     

MySQL 5.7的多源复制

MySQL 5.7已经开始支持了多源复制,相信小伙们都很激动,MySQL 5.7之前只能实现一主一从.一主多从或者多主多从的复制,如果想实现多主一从的复制,只好使用MariaDB,但是MariaDB又与官方的MySQL版本不兼容的,在MySQL 5.7版本已经可以实现多主一从的复制了.MySQL 5.7版本相比之前的版本,无论在功能还是性能.安全等方面都已经提升了不少,值得大家去研究和使用. MySQL 5.7版本之前的最常见的复制方式,一主一从或者一主多从的架构: MySQL 5.7之后就可以

基于GTID的MySQL多源复制配置

多源复制的意义 1.可以在一个从库上对多个服务器的数据库进行汇总,或者对一个数据库的分库分表进行汇总. 2.集约使用从库服务器的硬件资源,毕竟弱一个数据库业务量较小确占用整个服务器资源是不经济的. 3.更方便的对个业务库进行数据备份,优化数据库备份脚本编写逻辑 拓补图 实施步骤 1.备份主库上的数据,考虑到gtid的问题建议只采用mysqldump程序进行备份 centos:#mysqldump --login-path=3306 \ #mysql官方工具都支持login-path快速登录   

mysql 多源复制

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_in

MySQL多源复制搭建

1.1     实验概要 1.1.1  实验假设 本实验假设已经完成操作系统和MySQL安装部署. 1.1.2  实验目的 MySQL5.7的多源复制技术搭建部署,然后简单测试. 1.1.3  环境信息 操作系统 MySQL版本 服务器地址 服务器角色 Centos7 5.7.18 192.168.102.23 source 1 Centos7 5.7.18 192.168.102.24 source 2 Centos7 5.7.18 192.168.102.25 target 1.1.4  实

mysql第四篇文章~关于mysql的多源复制

一 场景需求 多源复制版本 5.7,目标主机5.6.21 4个DB机器的某些数据库需要数据汇总进行连表查询 二 进行搭建  1 导出相应的目的库     mysqldump -uuser -ppassword --master-data=2 --single-transaction --databases --add-drop-database dbname >dbname.sql  2 将相应的目的库导入到多源复制机器上     注意 5.6版本 需要先删除第一行,否则无法导入.     my

mysql多源复制详解

大家应该知道,mysql比起其他数据库,最大的特色是就是主从复制,不过5.7之前的版本最多就只支持一主多从的复制方式,对于一些统计类的需求,就需要跨库,这是比较麻烦的事情,以往只能交由数据库中间件(mycat等)去做这种事情,还有备份操作,也只能一个个库的用脚本去轮询或并发备份,不可谓不费时费力.然后,多源复制的概念出来了. 多源复制的概念最早是mariadb社区提出的,后来mysql官方积极引入到5.7的版本中来(5.6最新版也是没有这个功能的),percona就不说了,也是随后推出.这个功能