This article explains how to create or upgrade an ApsaraDB RDS for MySQL native replication instance. It also covers the permissions and limitations of this feature.
Prerequisites
To create a new native replication instance or upgrade an existing instance, your instance must meet the following requirements. You can view the instance details on the Basic Information page.
-
Database version: MySQL 5.7 (minor version 20240930 or later) or MySQL 8.0 (minor version 20250531 or later)
-
Product series: Basic Edition
-
Billing method: subscription, pay-as-you-go
NoteTo use a Serverless native replication instance, you must first create a pay-as-you-go instance, enable native replication, and then change the billing method to Serverless.
-
Supported regions: China (Shanghai), China (Beijing), China (Shenzhen), China (Guangzhou), and China (Chengdu)
ImportantNative replication for ApsaraDB RDS is currently available only in the regions listed above. Support for other regions will be added in the future. If you require this feature in other regions, please submit a ticket.
Billing
-
If you enable native replication when you purchase a new instance, you are charged standard fees for the new instance. Upgrading an existing instance to a native replication instance does not incur additional fees.
-
During the full data import to your ApsaraDB RDS for MySQL instance, if you choose to upload a backup of your self-managed database to Object Storage Service (OSS) and then download it to RDS, you will incur OSS storage fees while the backup is stored in OSS.
Native Replication Permissions
A privileged account on an ApsaraDB RDS for MySQL native replication instance has permissions that are unavailable on standard ApsaraDB RDS for MySQL instances.
Replication command permissions
On a native replication instance, the privileged account can run the following native MySQL replication commands.
-
Configure replication between a source database and a replica database:
CHANGE MASTER TO. For more information, see CHANGE MASTER TO. -
Start the replication process:
START SLAVE;. For more information, see START SLAVE. -
Stop the replication process:
STOP SLAVE;. For more information, see STOP SLAVE. -
Reset the state of the replica database to restart the replication process from the source database:
RESET SLAVE;. For more information, see RESET SLAVE.
Parameter modification permissions
On a native replication instance, the privileged account can run the following SQL statements to modify runtime parameters.
-
Set the read-only mode for the database server.
SET GLOBAL read_only = ON/OFF;When set to ON, the server enters read-only mode. When set to OFF, the read-only mode is disabled, and read/write operations are allowed.
-
Control whether SQL statements executed in the current session are written to the binary log.
SET SESSION sql_log_bin = ON/OFF;When set to ON, SQL operations in the session are recorded in the binary log. When set to OFF, SQL statements executed in the session are not recorded in the binary log.
-
Set the next Global Transaction Identifier (GTID).
SET SESSION GTID_NEXT = "your_gtid_value";
During maintenance operations such as instance migration or specification changes, the permissions to run native replication commands and modify parameters are temporarily revoked. This does not affect the instance's replication process. The system restores the permissions after the maintenance task is complete.
Notes
ApsaraDB RDS for MySQL native replication instances have the following limitations:
Limitations
-
The instance becomes read-only.
-
Major version upgrades are not supported.
-
Upgrading the product series (for example, from Basic Edition to High-availability Edition or Cluster Edition) is not supported.
-
Switching the Virtual Private Cloud (VPC) is not supported.
-
Database and table recovery is not supported.
-
When you upgrade an existing instance to a native replication instance, a transient connection failure of about 30 seconds may occur. We recommend that you perform this operation during off-peak hours and ensure that your application has a reconnection mechanism.
Permission limitations
-
Privileged account limitations
Some SUPER privileges required for native replication are granted only to the privileged account of the ApsaraDB RDS for MySQL instance. Only the privileged account can run native commands such as
CHANGE MASTERandSTART SLAVE. -
Replication privilege allowlist
When native replication applies external binary log events, it first checks privileges. RDS does not apply any operation that requires privileges beyond the following list, which causes replication to stop.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO XXX; -
System database limitations
All operations on system databases are ignored, including
mysql,sys,information_schema,performance_schema, and__recyclebin__.NoteRDS does not ignore operations that indirectly modify system databases, such as CREATE USER and GRANT. However, the SQL statements must comply with the replication privilege allowlist. A privilege escalation operation, such as
GRANT super on *.* to xxx;, will stop replication. -
GTID limitations
In a MySQL native replication configuration, the source and replica databases must use the same Global Transaction Identifier (GTID) mode, either both enabled or both disabled. ApsaraDB RDS for MySQL does not support disabling GTID mode. Therefore, if you want to use an ApsaraDB RDS for MySQL instance as a replica for an external source database, the external source database must have GTID mode enabled for compatibility.
Before you set up the replication, run
SHOW VARIABLES LIKE 'gtid_mode';on the external source database to check whether GTID mode is enabled. If it is not enabled, runSET GLOBAL gtid_mode=ON;to enable it.
Upgrade to a native replication instance
New instance
When you purchase a new ApsaraDB RDS for MySQL instance (standard creation page), expand More at the bottom of the page and enable the Native Replication switch. Note that the native replication option is displayed only when the instance meets the prerequisites.
Existing instance
When you upgrade an existing instance to a native replication instance, a transient connection failure of about 30 seconds may occur. We recommend that you perform this operation during off-peak hours and ensure that your application has a reconnection mechanism.
-
Go to the RDS Instances list, select a region, and click the ID of the target instance. The target instance must meet the prerequisites.
-
In the left navigation bar, click Native Replication, and click Enable on the page.
-
Read the information in the dialog box carefully and click Yes.
NoteIf you have not authorized the official ApsaraDB RDS service account to access your OSS bucket, and to create and attach an elastic network interface (ENI) in your account, select the corresponding check boxes to grant the permissions.
Step 2: Set up data replication
-
Install Percona XtraBackup on the self-managed database and perform a backup
-
Install Percona XtraBackup:
Install on CentOS
-
MySQL 5.7
wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.29/binary/redhat/8/x86_64/percona-xtrabackup-24-2.4.29-1.el8.x86_64.rpm yum localinstall percona-xtrabackup-24-2.4.29-1.el8.x86_64.rpm -
MySQL 8.0
wget https://downloads.percona.com/downloads/Percona-XtraBackup-8.0/Percona-XtraBackup-8.0.35-31/binary/redhat/8/x86_64/percona-xtrabackup-80-8.0.35-31.1.el8.x86_64.rpm yum localinstall percona-xtrabackup-80-8.0.35-31.1.el8.x86_64.rpm
Install on Ubuntu
-
Install Percona XtraBackup.
-
MySQL 5.7
# 1. Download the Percona repository package. wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb # 2. Install the repository package. sudo dpkg -i percona-release_latest.generic_all.deb # 3. Update the package lists. sudo apt-get update # 4. Install Percona XtraBackup. sudo apt-get install -y percona-xtrabackup-24 -
MySQL 8.0
# 1. Download the Percona repository package (if not done in a previous step). wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb # 2. Install the repository package. sudo dpkg -i percona-release_latest.generic_all.deb # 3. Update the package lists. sudo apt-get update # 4. Install Percona XtraBackup. sudo apt-get install -y percona-xtrabackup-80
-
-
Install qpress. Percona XtraBackup for Ubuntu does not include qpress, so you must install it separately.
sudo apt-get install -y qpress
-
-
Create a backup.
The following three compression methods are based on the
xtrabackupcommand and are suitable for instances that primarily use the InnoDB engine. If your database contains MyISAM tables, use theinnobackupexcommand.Default qpress compression
xtrabackup --backup \ --host=127.0.0.1 \ --port=3306 \ --user=<your_user> \ --password=<your_password> \ --stream=xbstream \ --compress > ./<your_backup.xb>QuickLZ compression
This method requires Percona XtraBackup 8.0.34-29 or earlier. For more information, see the official Percona XtraBackup documentation.
xtrabackup --backup \ --host=127.0.0.1 \ --port=3306 \ --user=<your_user> \ --password=<your_password> \ --stream=xbstream \ --compress > ./<your_backup_qp.xb>External ZSTD compression
xtrabackup --backup \ --host=127.0.0.1 \ --port=3306 \ --user=<your_user> \ --password=<your_password> \ --stream=xbstream \ | zstd -q - > ./<your_backup.xb.zstd>
-
-
Import full data and automatically set up data replication
NoteBefore you import data, ensure that a network connection exists between your self-managed MySQL database and your ApsaraDB RDS for MySQL instance.
Download from OSS
-
Upload the self-managed database backup to OSS
You can use various tools, such as the ossutil tool or OSS SDKs, to upload the backup file. This topic uses ossutil as an example.
ImportantMake sure that the destination OSS Bucket and the ApsaraDB RDS for MySQL instance are in the same region. Otherwise, RDS will fail to retrieve the backup file from OSS.
-
Install ossutil.
yum install -y unzip sudo -v ; curl https://gosspublic.alicdn.com/ossutil/install.sh | sudo bash ossutil config -
Upload the backup data to OSS.
ossutil -e <your_oss_endpoint> -i <your_accesskey_id> -k <your_accesskey_secret> cp <your_backup_file> oss://<your_bucket_name>/
-
-
Import the backup file from OSS to RDS and automatically set up the replication link
-
Go to the RDS Instances list, select a region, and then click the ID of the destination instance.
-
In the left navigation bar, click Native Replication.
-
On the native replication page, click Import Full Data, configure the following parameters, and click Yes.
Category
Parameter
Description
Backup Import Configuration (Required)
MySQL Version
The system automatically displays 5.7 or 8.0. No configuration is required.
Method
Select Import from OSS.
OSS Bucket
Select the OSS bucket where the backup file of the self-managed database is stored. For more information about OSS buckets, see Upload files.
OSS File Name
Select the backup file for the self-managed database from the OSS bucket. If the backup file is in a subdirectory of the OSS bucket, you must manually enter the full path name to search for it. The following three backup file formats are supported:
-
An
xbstreamfile generated by Percona XtraBackup. -
A
_qp.xbfile generated by using the built-in QuickLZ compression of Percona XtraBackup. -
An
xbstreamfile compressed by using zstd, with a.xb.zstfile extension.
We recommend that you enable automatic replication setup. The system will automatically set up the data replication link based on the following configurations. If you do not enable automatic replication setup, you must manually set up the replication link after you import the full data.
Automatic Replication Setup (Optional)
Auto-setup Replication
Turn on this switch to automatically establish a replication relationship from the self-managed MySQL database to the ApsaraDB RDS for MySQL instance.
Source IP
Enter the IP address of the source self-managed database.
Source Port
Enter the port number of the source self-managed database.
Source Account
Enter the username for the source self-managed database. The user must have the
REPLICATION CLIENTandREPLICATION SLAVEprivileges.Source Account Password
Enter the password for the source user account.
-
-
Stream backup directly
-
Install the backup-helper tool on the self-managed database and start the backup transfer process
# Install the backup-helper tool. wget -O backup-helper https://mysql-backup-helper.oss-cn-beijing.aliyuncs.com/v1.0.0-alpha/backup-helper && chmod +x backup-helper # Start the backup transfer process. # Make sure that MySQL is running and the corresponding version of Percona XtraBackup is installed. ./backup-helper --backup --mode=stream --host=<mysql_ip> --port=<mysql_port> --user=<mysql_user> --password=<mysql_password> -
Import data into RDS
-
Log on to the ApsaraDB RDS console, select a region, and then click the ID of the destination instance.
-
In the left navigation bar, click Native Replication.
-
On the native replication page, click Import Full Data, configure the following parameters, and click Yes.
Category
Parameter
Description
Backup Import Configuration (Required)
MySQL Version
The system automatically displays 5.7 or 8.0. No configuration is required.
Method
Select Import from Stream Backup.
Source Backup IP Address
Enter the IP address used for the backup transfer.
Source Backup Port
Enter the port used for the backup transfer. The default port is 9999.
We recommend that you enable automatic replication setup. The system will automatically set up the data replication link based on the following configurations. If you do not enable automatic replication setup, you must manually set up the replication link after you import the full data.
Automatic Replication Setup (Optional)
Auto-setup Replication
Turn on this switch to automatically establish a replication relationship from the self-managed MySQL database to the ApsaraDB RDS for MySQL instance.
Source IP
Enter the IP address of the source self-managed database.
Source Port
Enter the port number of the source self-managed database.
Source Account
Enter the username for the source self-managed database. The user must have the
REPLICATION CLIENTandREPLICATION SLAVEprivileges.Source Account Password
Enter the password for the source user account.
-
If you did not select Auto-setup Replication when you imported the full data, or if the automatic replication link encounters an issue and cannot be recovered, you can refer to the following steps to manually establish a data replication link from a self-managed MySQL database to an ApsaraDB RDS for MySQL instance.
-
-
Check the replication status
Return to the Native Replication page of the RDS instance details to view the data replication link information. When the replication status is Running, it indicates that the data replication link has been successfully established.
Disable native replication
-
Go to the RDS Instances list, select a region, and then click the ID of the target instance. The instance must be a native replication instance.
-
In the left navigation bar, click Native Replication, and then click Disable.
-
Click Yes.
ImportantAfter you click OK, the replication relationship between the self-managed MySQL database and the ApsaraDB RDS for MySQL native replication instance terminates. The instance then reverts to a standard ApsaraDB RDS for MySQL instance and switches from read-only to read/write mode, allowing you to perform write operations.
Related content and API
-
To create an ApsaraDB RDS for MySQL native replication instance, you can call the CreateDBInstance API operation. Note the following:
-
The basic instance configuration must meet the prerequisites. You can configure other parameters as required.
-
Set the ExternalReplication parameter to ON.
-
-
To set up a native replication link for an existing instance, you can call the ImportUserBackupFile API operation.
Appendix: Network configuration
For more information about network connectivity issues, see Connections and networking.
|
Scenario |
Use case |
Configuration method |
Fees |
|
Access between resources in the same VPC |
A self-managed MySQL database on an ECS instance |
Within the same VPC, network connectivity is available by default and requires no additional configuration. You only need to configure the security group to allow inbound traffic on port 3306 from the IP address of the RDS instance to the security group of the ECS instance. After you connect to the ApsaraDB RDS for MySQL native replication instance, you can run the |
None |
|
Access between resources in different VPCs |
Cross-VPC and cross-region data synchronization on Alibaba Cloud |
|
|
|
Access between an on-premises data center and a cloud-based RDS instance |
Replication from a self-managed database in a data center to an RDS native replication instance |
You can use a VPN Gateway or Express Connect to connect the network of the data center to the VPC where the RDS native replication instance resides. |
Fees vary based on the method used. For more information, see the official documentation. |
|
Cross-cloud access |
Replication from a database on another cloud to an RDS native replication instance |
In a multi-cloud environment, access requires a cross-cloud network connection. For an RDS native replication scenario where RDS is the source and a database on another cloud is the destination, you can use the network services provided by the other cloud, such as a VPN or a leased line, to establish a network connection. |
Fees vary based on the method used. For more information, see the official documentation. |
|
Public network access (not recommended) |
N/A |
RDS native replication instances support access to external nodes over the internet. However, we do not recommend this method due to security risks. |
Fees vary based on the method used. For more information, see the official documentation. |