文档

使用MySQL作为PolarDB-X的Slave

更新时间:

说明

  • PolarDB-X兼容MySQL的复制协议,因此可以将MySQL配置为PolarDB-X的Slave,在MySQL上执行如下示例中的SQL可以对从PolarDB-X到MySQL的复制链路进行管理,更多数据复制相关SQL可参看MySQL官方文档。

  • 如果您的PolarDB-X实例是兼容MySQL 5.7的版本,请使用5.7版本的MySQL作为PolarDB-X的Slave;如果您的PolarDB-X实例是兼容MySQL 8.0的版本,请使用8.0版本的MySQL作为PolarDB-X的Slave,推荐使用8.0.27及以上的版本。

  • 如果您开通了binlog多流服务,当基于binlog多流服务配置MySQL作为PolarDB-X的Slave时,需要为每条binlog日志流分别创建复制链路,可以在单个MySQL实例上配置多条复制链路,也可以选择为每条binlog日志流配置一个独立的MySQL Slave实例。如果选择在单个MySQL实例上配置多条复制链路,DDL的广播复制是一个难点问题。

操作方法

  • 创建复制链路

    CHANGE MASTER TO option [, option] ... [ channel_option ]
    
    option: {
        MASTER_BIND = 'interface_name'
      | MASTER_HOST = 'host_name'
      | MASTER_USER = 'user_name'
      | MASTER_PASSWORD = 'password'
      | MASTER_PORT = port_num
      | PRIVILEGE_CHECKS_USER = {'account' | NULL}
      | REQUIRE_ROW_FORMAT = {0|1}
      | REQUIRE_TABLE_PRIMARY_KEY_CHECK = {STREAM | ON | OFF}
      | ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = {OFF | LOCAL | uuid}
      | MASTER_LOG_FILE = 'source_log_name'
      | MASTER_LOG_POS = source_log_pos
      | MASTER_AUTO_POSITION = {0|1}
      | RELAY_LOG_FILE = 'relay_log_name'
      | RELAY_LOG_POS = relay_log_pos
      | MASTER_HEARTBEAT_PERIOD = interval
      | MASTER_CONNECT_RETRY = interval
      | MASTER_RETRY_COUNT = count
      | SOURCE_CONNECTION_AUTO_FAILOVER = {0|1}
      | MASTER_DELAY = interval
      | MASTER_COMPRESSION_ALGORITHMS = 'value'
      | MASTER_ZSTD_COMPRESSION_LEVEL = level
      | MASTER_SSL = {0|1}
      | MASTER_SSL_CA = 'ca_file_name'
      | MASTER_SSL_CAPATH = 'ca_directory_name'
      | MASTER_SSL_CERT = 'cert_file_name'
      | MASTER_SSL_CRL = 'crl_file_name'
      | MASTER_SSL_CRLPATH = 'crl_directory_name'
      | MASTER_SSL_KEY = 'key_file_name'
      | MASTER_SSL_CIPHER = 'cipher_list'
      | MASTER_SSL_VERIFY_SERVER_CERT = {0|1}
      | MASTER_TLS_VERSION = 'protocol_list'
      | MASTER_TLS_CIPHERSUITES = 'ciphersuite_list'
      | MASTER_PUBLIC_KEY_PATH = 'key_file_name'
      | GET_MASTER_PUBLIC_KEY = {0|1}
      | NETWORK_NAMESPACE = 'namespace'
      | IGNORE_SERVER_IDS = (server_id_list)
    }
    
    channel_option:
        FOR CHANNEL channel
    
    server_id_list:
        [server_id [, server_id] ... ]
  • 开始数据复制

    START {SLAVE | REPLICA}
  • 停止数据复制

    STOP {SLAVE | REPLICA}
  • 重置数据复制进程(需要先停止数据复制进程)

    RESET {SLAVE | REPLICA} [ALL] [channel_option]
    
    channel_option:
        FOR CHANNEL channel