zoukankan      html  css  js  c++  java
  • 初试mysql5.7.2新特性:多源复制(MySQL 5.7 multi-source replication)

    多源复制和多主复制的区别:

    多主复制示意图:

    Multi master replication

    多源复制示意图:

    Multi source replication

    在my.cnf中添加crash safe特性参数:
    master_info_repository=TABLE;
    relay_log_info_repository=TABLE;


    mysql> change master to master_host="10.186.21.102", master_port=13306, master_user="repl",master_password="repl" for channel="master1";
    Query OK, 0 rows affected(0.01 sec)

    mysql> change master to master_host="10.186.21.102", master_port=13307, master_user="repl",master_password="repl" for channel="master2";
    Query OK, 0 rows affected (0.01 sec)

    mysql> select * from mysql.slave_master_info;
    +-----------------+-----------------+----------------+---------------+-----------+---------------+-------+---------------+-------------+--------+------------+----------+------------+---------+------------------------+-----------+------+--------------------+------+-------------+---------+-------------+-----------------------+--------------+
    | Number_of_lines | Master_log_name | Master_log_pos | Host          | User_name | User_password | Port  | Connect_retry | Enabled_ssl | Ssl_ca | Ssl_capath | Ssl_cert | Ssl_cipher | Ssl_key | Ssl_verify_server_cert | Heartbeat | Bind | Ignored_server_ids | Uuid | Retry_count | Ssl_crl | Ssl_crlpath | Enabled_auto_position | Channel_name |
    +-----------------+-----------------+----------------+---------------+-----------+---------------+-------+---------------+-------------+--------+------------+----------+------------+---------+------------------------+-----------+------+--------------------+------+-------------+---------+-------------+-----------------------+--------------+
    |              24 |                 |              4 | 10.186.21.102 | repl      | repl          | 13306 |            60 |           0 |        |            |          |            |         |                      0 |      1800 |      | 0                  |      |       86400 |         |             |                     0 | master1      |
    |              24 |                 |              4 | 10.186.21.102 | repl      | repl          | 13307 |            60 |           0 |        |            |          |            |         |                      0 |      1800 |      | 0                  |      |       86400 |         |             |                     0 | master2      |
    +-----------------+-----------------+----------------+---------------+-----------+---------------+-------+---------------+-------------+--------+------------+----------+------------+---------+------------------------+-----------+------+--------------------+------+-------------+---------+-------------+-----------------------+--------------+
    2 rows in set (0.00 sec)

    mysql> select * from slave_relay_log_info  ;
    +-----------------+------------------------------------+---------------+-----------------+----------------+-----------+-------------------+----+--------------+
    | Number_of_lines | Relay_log_name                     | Relay_log_pos | Master_log_name | Master_log_pos | Sql_delay | Number_of_workers | Id | Channel_name |
    +-----------------+------------------------------------+---------------+-----------------+----------------+-----------+-------------------+----+--------------+
    |               7 | ./mha-db1-relay-bin-master1.000001 |             4 |                 |              0 |         0 |                 0 |  1 | master1      |
    |               7 | ./mha-db1-relay-bin-master2.000001 |             4 |                 |              0 |         0 |                 0 |  1 | master2      |
    +-----------------+------------------------------------+---------------+-----------------+----------------+-----------+-------------------+----+--------------+

    mysql> start slave for channel="master2";
    Query OK, 0 rows affected (0.01 sec)

    mysql> start slave for channel="master1";
    Query OK, 0 rows affected (0.01 sec)

    mysql> show slave status for channel="master1"G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 10.186.21.102
                      Master_User: repl
                      Master_Port: 13306
                    Connect_Retry: 60
                  Master_Log_File: log_bin.000001
              Read_Master_Log_Pos: 120
                   Relay_Log_File: mha-db1-relay-bin-master1.000002
                    Relay_Log_Pos: 281
            Relay_Master_Log_File: log_bin.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: 120
                  Relay_Log_Space: 464
                  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: 13306
                      Master_UUID: 546b04cc-9621-11e3-95d5-0a98756bb836
                 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 the slave I/O thread to update it
               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: 0
    1 row in set (0.00 sec)

    mysql> show slave status for channel="master2"G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 10.186.21.102
                      Master_User: repl
                      Master_Port: 13307
                    Connect_Retry: 60
                  Master_Log_File: log_bin.000001
              Read_Master_Log_Pos: 120
                   Relay_Log_File: mha-db1-relay-bin-master2.000002
                    Relay_Log_Pos: 281
            Relay_Master_Log_File: log_bin.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: 120
                  Relay_Log_Space: 464
                  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: 13307
                      Master_UUID: fba8d917-9621-11e3-95d9-0a98756bb836
                 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 the slave I/O thread to update it
               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: 0
    1 row in set (0.00 sec)

    master1:
    mysql> create database master1;

    master2:
    mysql> create database master2;

    slave:
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | master1            |
    | master2            |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    6 rows in set (0.00 sec)

    重启slave命令:
    mysql> stop slave for channel="master1";
    Query OK, 0 rows affected (0.00 sec)

    mysql> stop slave for channel="master2";
    Query OK, 0 rows affected (0.01 sec)

    重做slave命令:
    mysql> reset slave for channel="master2";
    Query OK, 0 rows affected (0.33 sec)

    mysql> reset slave for channel="master1";
    Query OK, 0 rows affected (0.30 sec)

     

     多源复制存在问题:

    多源数据库不能有同名库,否则会导致复制失败

    master1:

    mysql> create database master1;

    Query OK, 1 row affected (0.00 sec)

    master2:

    mysql> create database master2;

    Query OK, 1 row affected (0.00 sec)

    mysql> create database master1;

    Query OK, 1 row affected (0.00 sec)

    slave:

    show slave status for channel="master2"G;

    Last_SQL_Error: Error 'Can't create database 'master2'; database exists' on query. Default database: 'master2'. Query: 'create database master2'

  • 相关阅读:
    毕业设计论文撰写指南(10)—— 总体要求
    毕业设计论文撰写指南(09)—— 致谢+参考文献
    毕业设计论文撰写指南(08)—— 第六章 结论
    毕业设计论文撰写指南(07)—— 第五章 ***系统详细设计与实现
    Interlocked.CompareExchange
    Memcached、Redis和MongoDB的区别
    relatedTarget、fromElement、toElement之间的关系
    异常:System.BadImageFormatException,未能加载正确的程序集XXX
    Windows Service
    启用 CORS 来解决这个问题(ajax跨域请求)
  • 原文地址:https://www.cnblogs.com/simplelogic/p/3550960.html
Copyright © 2011-2022 走看看