Establishes a primary/secondary replication link by configuring the current PolarDB-X instance as a secondary instance of a MySQL or PolarDB-X primary 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
Supported in PolarDB-X V5.4.19 and later.
Due to network restrictions, this statement applies only to self-managed instances. Replication links cannot be created for PolarDB-X instances purchased through the Alibaba Cloud Management Console.
Run this statement using a privileged account of the current instance.
The account specified to connect to the primary instance must also be a privileged account.
Parameters
| Parameter | Description | Default |
|---|---|---|
MASTER_HOST | The address of the primary instance. | — |
MASTER_USER | The username for connecting to the primary instance. | — |
MASTER_PASSWORD | The password for connecting to the primary instance. | — |
MASTER_PORT | The port for connecting to the primary instance. | — |
MASTER_LOG_FILE | The name of the log file on the primary instance. | — |
MASTER_LOG_POS | The offset in the log file from which binlog replication starts. | — |
MASTER_LOG_TIME_SECOND | The start time for replication, expressed as a UNIX timestamp (seconds since 1970-01-01 00:00:00 UTC). Ignored if MASTER_LOG_FILE and MASTER_LOG_POS are set. | — |
SOURCE_HOST_TYPE | The type of the primary instance. Set to POLARDBX when the primary instance is a PolarDB-X 2.0 instance. Valid values: RDS, POLARDBX, MYSQL. | MYSQL |
STREAM_GROUP | The name of the stream group. Required when the primary instance is a PolarDB-X 2.0 instance and you want to use its multi-stream binlog service. | — |
WRITE_SERVER_ID | The ID of the write server. | — |
TRIGGER_AUTO_POSITION | Specifies whether to automatically use the latest offset of the primary instance. | FALSE |
WRITE_TYPE | The write mode. Valid values: SPLIT (non-transactional parallel replication), SERIAL (non-transactional serial replication), TRANSACTION (transactional serial replication). | SPLIT |
MODE | The synchronization mode. Valid values: INCREMENTAL (incremental data synchronization only), IMAGE (schema synchronization, full data synchronization, and incremental data synchronization). | — |
CONFLICT_STRATEGY | The conflict policy. Valid values: OVERWRITE (overwrite conflicting data using REPLACE INTO), INTERRUPT (stop replication on conflict), IGNORE (skip conflicting data), DIRECT_OVERWRITE. | OVERWRITE |
IGNORE_SERVER_IDS | The IDs of servers to exclude from replication. | — |
FOR CHANNEL | The name of the replication link. Must be unique across existing link names. | — |
Examples
Start replication from a timestamp
Create a replication link and start synchronization from timestamp 1713159938 (2024-04-15 13:45:38):
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';Start replication from a log file offset
Create a replication link and start synchronization from offset 4 in the binlog.000001 file:
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';