Synchronize data in real time from PolarDB for MySQL to ApsaraDB RDS for MySQL by using DTS.
Prerequisites
- A PolarDB for MySQL cluster is created. Create a PolarDB for MySQL cluster.
- binary logging for the PolarDB for MySQL cluster is enabled. Enable binary logging.
Usage notes
-
During initial full data synchronization, DTS consumes read and write resources from the source and destination databases, which increases the database load. If database performance is poor, instance specifications are low, or business traffic is heavy (for example, the source database has many slow SQL queries or tables without primary keys, or the destination database experiences deadlocks), the database load increases and may even cause the service to become unavailable. Before you synchronize data, evaluate the performance of your source and destination instances. We recommend performing data synchronization during off-peak hours, for example, when the CPU utilization of both instances is below 30%.
- During initial full data synchronization, concurrent INSERT operations cause table fragmentation in the target cluster, resulting in a larger tablespace than the source database.
- If a source table lacks a primary key or unique constraint and contains duplicate rows, duplicate data may exist in the target database.
- If the target is an ApsaraDB RDS for MySQL instance (except MySQL 5.7 and 8.0), DTS creates an account named dtssyncwriter in the target database. This account has write permissions and is used only by DTS.
Billing
Synchronization type | Pricing |
Schema synchronization and full data synchronization | Free of charge. |
Incremental data synchronization | Charged. For more information, see Billing overview. |
Supported SQL operations
|
Operation type |
SQL statement |
|
DML |
INSERT, UPDATE, DELETE, and REPLACE |
|
DDL |
|
Supported synchronization topologies
-
One-way one-to-one synchronization
-
One-way one-to-many synchronization
-
One-way cascade synchronization
-
One-way many-to-one synchronization
Each topology has specific usage notes. Synchronization topologies.
Limitations
-
Incompatible with triggers
If you synchronize an entire database and a trigger within that database updates another table in the same database, data inconsistency may occur between the source and destination databases. For a solution, see Configure a data synchronization or migration task for a source database that contains a trigger.
-
RENAME TABLE limitations
The
RENAME TABLEoperation can cause data inconsistency. For example, if you select only Table A for synchronization and it is renamed to Table B in the source instance, Table B is not synchronized to the destination instance. To prevent this issue, select the entire database that contains both Table A and Table B as the synchronization object when you configure the data synchronization task.
Procedure
- Purchase a data synchronization instance. Purchase process.
Note When you purchase the instance, set PolarDB to PolarDB, MySQL to MySQL, and One-way Synchronization to One-way Synchronization.
-
Log on to the DTS console.
NoteIf you are automatically redirected to the Data Management (DMS) console, you can click the
icon in the lower-right corner and then click
to return to the classic DTS console. -
In the left-side navigation pane, click Data Synchronization.
-
At the top of the Synchronization Tasks page, select the region where your destination instance is located.
-
Find the data synchronization task that you purchased and click Configure Task.
- Configure the source and target instances.
Category Parameter Description N/A Synchronization Task Name DTS auto-generates a task name. Specify a descriptive name for easy identification. Source Instance Information Instance Type Fixed as PolarDB Instance. Not editable. Instance Region The source region selected during purchase. Not editable. PolarDB Instance ID Select the source PolarDB for MySQL cluster ID. Database Account Enter the database account for the source PolarDB for MySQL cluster. Database Password Enter the password for the database account. Target Instance Information Instance Type Select RDS Instance. Instance Region The target region selected during purchase. Not editable. Database Account Enter the database account for the target RDS instance. Database Password Enter the password for the database account. Note If the target RDS instance runs MySQL 5.5 or MySQL 5.6, you do not need to configure Database Account and Database Password.Connection Method Select Non-encrypted or SSL-encrypted as needed. If you select SSL-encrypted, enable SSL encryption for the RDS instance first. Set SSL encryption. ImportantCurrently, the Encryption parameter is available only for regions in the Chinese mainland and the China (Hong Kong) region.
-
In the lower-right corner of the page, click Set Whitelist and Next.
If the source or destination database is an Alibaba Cloud database instance, such as an ApsaraDB RDS for MySQL or ApsaraDB for MongoDB instance, DTS automatically adds the CIDR blocks of DTS servers to the IP address whitelist of the instance. If the source or destination database is a self-managed database hosted on an Elastic Compute Service (ECS) instance, DTS automatically adds the CIDR blocks of DTS servers to the security group rules of the ECS instance, and you must make sure that the ECS instance can access the database. If the self-managed database is hosted on multiple ECS instances, you must manually add the CIDR blocks of DTS servers to the security group rules of each ECS instance. If the source or destination database is a self-managed database that is deployed in a data center or provided by a third-party cloud service provider, you must manually add the CIDR blocks of DTS servers to the IP address whitelist of the database to allow DTS to access the database. For more information, see Whitelist DTS server IP addresses.
WarningAdding the public IP address blocks of the DTS service, either automatically or manually, may pose security risks. Using this product, you acknowledge that you understand and accept the potential security risks and that you must implement basic security measures. These measures include, but are not limited to, strengthening password security, limiting the ports open to each CIDR block, using authentication for internal API calls, and regularly checking and restricting unnecessary CIDR blocks. Alternatively, you can connect through a private network using a leased line, VPN Gateway, or Smart Access Gateway.
-
Configure the processing mode for existing target tables and select the objects to synchronize.
Parameter
Description
Processing mode for existing target tables
-
Precheck and Report Errors: DTS checks for tables in the destination database with the same names as the source tables. If no conflicts are found, the precheck passes. If a name conflict exists, the precheck fails and the task stops.
NoteIf you cannot delete or rename the conflicting tables in the destination database, you can Set object names in the destination instance to avoid name conflicts.
-
Ignore Errors and Proceed: Skips the check for tables with conflicting names in the destination database.
WarningSelecting Ignore Errors and Proceed may cause data inconsistency and other risks. For example:
-
If the table schemas are identical, existing records in the destination table that share a primary key with source records are not changed during initial synchronization. However, they will be overwritten by changes from the source during incremental synchronization.
-
If the table schemas are different, the initial synchronization may fail to transfer some columns or may fail entirely.
-
Select synchronization objects
In the Source Objects box, click the objects that you want to synchronize, and then click the
icon to move them to the Selected Objects box.You can select databases and tables as synchronization objects.
Note-
If you select an entire database, all schema changes for objects within that database are synchronized to the destination database.
-
By default, object names are not changed. To rename objects in the destination cluster, use the object name mapping feature. For more information, see Set object names in the destination instance.
Map or rename objects
Change the names of synchronized objects in the destination instance. For more information, see Map databases, tables, and columns.
Replicate temporary tables from DMS online DDL operations
If you use Data Management (DMS) to perform online DDL changes on the source database, you can choose whether to synchronize the temporary tables generated by the DDL changes.
-
Yes: Synchronizes the temporary tables generated by online DDL changes.
NoteIf a large amount of temporary table data is generated by online DDL changes, the data synchronization task may be delayed.
-
No: Does not synchronize the temporary tables generated by online DDL changes. Only the original DDL operations from the source database are synchronized.
NoteThis option causes tables in the destination database to be locked.
Connection retry period
If DTS cannot connect to the source or destination instance, it retries for 720 minutes (12 hours) by default. You can also specify a custom retry duration. If DTS reconnects to the source or destination instance within the specified duration, the synchronization task automatically resumes. Otherwise, the task fails.
NoteYou are billed for task run time during connection retries. Customize the retry duration based on your business needs, or release the DTS instance as soon as the source and destination instances are released.
-
-
After you complete the preceding configurations, click Next in the lower-right corner of the page.
-
Configure advanced settings for initial synchronization.
NoteThe initial synchronization types include initial schema synchronization and initial full data synchronization. If you select both Initial Schema Synchronization and Initial Full Data Synchronization, DTS synchronizes the schema and existing data of the selected objects from the source database to the destination database before starting incremental data synchronization.
-
After completing the preceding configurations, click Precheck and Start in the lower-right corner of the page.
Note-
A precheck runs before the synchronization task starts, and you can only start the task after it passes.
-
If the precheck fails, click the
icon next to the failed item to view the details.-
You can fix the issues based on the cause and run the precheck again.
-
If you do not need to fix the items that triggered warnings, you can click Ignore or Ignore Warnings and Rerun Precheck to skip the warnings and run the precheck again.
-
-
-
After the Precheck dialog box displays Precheck Passed, close the Precheck dialog box. The synchronization task starts automatically.
-
Wait for the task to finish initialization and enter the Synchronizing state.
You can view the status of the data synchronization task on the Data Synchronization page.