All Products
Search
Document Center

PolarDB:CHANGE MASTER TO

Last Updated:Jun 06, 2024

This topic describes how to execute the CHANGE MASTER TO statement to establish a primary/secondary replication link by specifying the current PolarDB-X instance as a secondary instance of a MySQL or PolarDB-X instance.

Syntax

CHANGE MASTER TO option [, option] ... [ channel_option ]

option: {
    MASTER_HOST = 'host_name'
  | MASTER_USER = 'user_name'
  | MASTER_PASSWORD = 'password'
  | MASTER_PORT = port_num
  | MASTER_LOG_FILE = 'source_log_name'
  | MASTER_LOG_POS = source_log_pos
  | MASTER_LOG_TIME_SECOND = source_log_time
  | SOURCE_HOST_TYPE = {RDS|POLARDBX|MYSQL}
  | STREAM_GROUP = 'stream_group_name'
  | WRITE_SERVER_ID = write_server_id
  | TRIGGER_AUTO_POSITION = {FALSE|TRUE}
  | WRITE_TYPE = {SPLIT|SERIAL|TRANSACTION}
  | MODE = {INCREMENTAL|IMAGE}
  | CONFLICT_STRATEGY = {OVERWRITE|INTERRUPT|IGNORE|DIRECT_OVERWRITE}
  | IGNORE_SERVER_IDS = (server_id_list)
}

channel_option:
    FOR CHANNEL channel

server_id_list:
    [server_id [, server_id] ... ]

Usage notes

  • This SQL statement is supported by PolarDB-X V5.4.19 or later.

  • Due to network restrictions, you cannot create replication links for PolarDB-X instances that are purchased by using the Alibaba Cloud Management Console. This statement applies only to self-managed instances.

  • You must use a privileged account of the current instance to execute the CHANGE MASTER TO statement.

  • The account that you specify in the CHANGE MASTER TO statement to connect to the primary instance must be a privileged account.

Parameters

  • MASTER_HOST: the address of the primary instance.

  • MASTER_USER: the username that is used to connect to the primary instance.

  • MASTER_PASSWORD: the password that is used to connect to the primary instance.

  • MASTER_PORT: the port number that is used to connect to the primary instance.

  • MASTER_LOG_FILE: the name of the log file on the primary instance.

  • MASTER_LOG_POS: the offset from which the binlog replication starts in the log file on the primary instance.

  • MASTER_LOG_TIME_SECOND: the time offset of the primary instance. The value is a UNIX timestamp representing the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. The MASTER_LOG_TIME_SECOND parameter is ignored if the MASTER_LOG_FILE and MASTER_LOG_POS parameters are configured to specify an exact offset.

  • SOURCE_HOST_TYPE: the type of the primary instance. Default value: MYSQL. If the primary instance is a PolarDB-X 2.0 instance, you must explicitly set this parameter to POLARDBX.

  • STREAM_GROUP: the name of the stream group if a multi-stream group is created. If the primary instance is a PolarDB-X 2.0 instance and you want to use the multi-stream binlog service of the primary instance, you must specify this parameter.

  • WRITE_SERVER_ID: the ID of the write server.

  • TRIGGER_AUTO_POSITION: specifies whether to automatically use the latest offset of the primary instance. Default value: FALSE.

  • WRITE_TYPE: the write mode. The default value is SPLIT, which indicates non-transactional parallel replication. A value of SERIAL indicates non-transactional serial replication, and a value of TRANSACTION indicates transactional serial replication.

  • MODE: the synchronization mode. A value of INCREMENTAL indicates incremental data synchronization, and a value of IMAGE indicates schema synchronization, full data synchronization, and incremental data synchronization.

  • CONFLICT_STRATEGY: the conflict policy. The default value is OVERWRITE, which indicates that the data with constraint violation is overwritten by executing the REPLACE INTO statement. A value of INTERRUPT indicates that the replication is interrupted, and a value of IGNORE indicates that the conflict is ignored.

  • IGNORE_SERVER_IDS: the ID of the server to ignore.

  • channel_option: the name of the link, which must be different from existing link names.

Example 1

Execute the following statement to create a replication link and start synchronization from 1713159938 (2024-04-15 13:45:38) in the log file:

CHANGE MASTER TO 
MASTER_HOST='pxc-YOURENDPOINT.com', 
MASTER_PORT=3306, 
MASTER_USER='polardbx', 
MASTER_PASSWORD='123456', 
SOURCE_HOST_TYPE=polardbx, 
MASTER_LOG_TIME_SECOND=1713159938, 
write_server_id=1944903859
FOR CHANNEL 'pxc-bjrcsnbyagcdxh';

Example 2

Execute the following statement to create a replication link and start synchronization from Offset 4 in the binlog.000001 file on the primary instance:

CHANGE MASTER TO 
MASTER_HOST='pxc-YOURENDPOINT.com', 
MASTER_PORT=3306, 
MASTER_USER='polardbx', 
MASTER_PASSWORD='123456', 
SOURCE_HOST_TYPE=polardbx, 
MASTER_LOG_FILE='binlog.000001', 
MASTER_LOG_POS=4, 
write_server_id=1944903859
FOR CHANNEL 'pxc-bjrcsnbyagcdxh';