• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 采用现有的复制设置

    作为创建新InnoDB ReplicaSet的替代方法,您还可以使用adoptFromAR带有选项的现有复制设置dba.createReplicaSet()。扫描复制设置,并且如果它与InnoDB ReplicaSet的前提条件兼容,则AdminAPI将创建必要的元数据。一旦采用了复制设置,则只能使用AdminAPI来管理InnoDB ReplicaSet。

    要将现有的复制设置转换为InnoDB ReplicaSet,请连接至主数据库,也称为主数据库。从连接MySQL Shell的全局会话的实例开始,将自动扫描并验证复制拓扑。在采用过程中会检查所有实例的配置,以确保它们与InnoDB ReplicaSet用法兼容。所有复制通道必须处于活动状态,并且通过GTID集验证的事务集必须保持一致。所有实例的数据集均应相同,但未经验证。属于拓扑的所有实例将自动添加到副本集。此操作对采用的副本集所做的唯一更改是元数据架构的创建。现有复制通道在采用期间不会更改,尽管可以在后续的主交换机操作中更改它们。

    例如,要在InnoDB ReplicaSet 上example1example2在InnoDB ReplicaSet 上采用由MySQL服务器实例组成的复制拓扑,请在以下位置连接到主数据库example1并发出:

    mysql-js> rs = dba.createReplicaSet('testadopt', {'adoptFromAR':1})
    A new replicaset with the topology visible from 'example1:3306' will be created.
    
    * Scanning replication topology...
    ** Scanning state of instance example1:3306
    ** Scanning state of instance example2:3306
    
    * Discovering async replication topology starting with example1:3306
    Discovered topology:
    - example1:3306: uuid=00371d66-3c45-11ea-804b-080027337932 read_only=no
    - example2:3306: uuid=59e4f26e-3c3c-11ea-8b65-080027337932 read_only=no
        - replicates from example1:3306
    source="localhost:3310" channel= status=ON receiver=ON applier=ON
    
    * Checking configuration of discovered instances...
    
    This instance reports its own address as example1:3306
    example1:3306: Instance configuration is suitable.
    
    This instance reports its own address as example2:3306
    example2:3306: Instance configuration is suitable.
    
    * Checking discovered replication topology...
    example1:3306 detected as the PRIMARY.
    Replication state of example2:3306 is OK.
    
    Validations completed successfully.
    
    * Updating metadata...
    
    ReplicaSet object successfully created for example1:3306.
    Use rs.add_instance() to add more asynchronously replicated instances to
    this replicaset and rs.status() to check its status.
    

    一旦采用了InnoDB ReplicaSet,就可以使用与从头创建的副本集相同的方式来使用它。从这一点出发,您必须仅使用AdminAPI来管理InnoDB ReplicaSet。