Synchronize RDS for MySQL to PolarDB for MySQL

Updated at:

Data Transmission Service (DTS) allows you to synchronize data from ApsaraDB RDS for MySQL to PolarDB for MySQL, a cloud-native distributed relational database fully compatible with MySQL.

Prerequisites

You have created a PolarDB for MySQL cluster. For more information, see Create a cluster manually.

Notes

  • During full data initialization, DTS consumes read and write resources of the source and destination databases, which may increase the database load. When the databases have low performance, low specifications, or heavy workloads (for example, a large number of slow SQL statements, tables without primary keys, or deadlocks on the destination database), the database pressure may be further increased and services may become unavailable. Therefore, you must evaluate the performance of the source and destination databases before starting data synchronization, and it is recommended that you perform data synchronization during off-peak hours (for example, when the CPU load of both the source and destination databases is below 30%).

  • During data synchronization, do not use tools such as gh-ost or pt-online-schema-change to perform online DDL operations on the synchronization objects in the source database. Otherwise, the synchronization task fails.

  • During initial full data synchronization, concurrent INSERT operations cause table fragmentation in the destination cluster. After the initial full data synchronization is complete, the tablespace of the destination cluster is larger than that of the source database.
  • If a table in the source database has no primary key or UNIQUE constraint, and its records are not unique across all fields, duplicate data may occur.

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

  • ALTER TABLE and ALTER VIEW

  • CREATE FUNCTION, CREATE INDEX, CREATE PROCEDURE, CREATE TABLE, and CREATE VIEW

  • DROP INDEX and DROP TABLE

  • RENAME TABLE

    Important

    RENAME TABLE operations may cause data inconsistency between the source and destination databases. For example, if you select a table as the object to be synchronized and rename the table during data synchronization, the data of this table is not synchronized to the destination database. To prevent this situation, you can select the database to which this table belongs as the object to be synchronized when you configure the data synchronization task. Make sure that the databases to which the table belongs before and after the RENAME TABLE operation are added to the objects to be synchronized.

  • TRUNCATE TABLE

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

For usage notes on each topology, see Synchronization topologies.

Limitations

  • DTS has limited compatibility with triggers.

    If you synchronize an entire database and a trigger in that database updates a table within the same database, data inconsistency may occur between the source and destination databases. For a solution, see How do I configure a synchronization or migration task if the source database contains triggers?.

  • The RENAME TABLE operation has limitations.

    The RENAME TABLE operation may cause data inconsistency. For example, if you synchronize only a specific table and that table is renamed in the source instance during synchronization, data from that table is not synchronized to the destination database. To prevent this issue, select the entire database to which the table belongs as the synchronization object during configuration.

Procedure

  1. Purchase a data synchronization instance. For more information, see Purchase a DTS instance.
    Note When purchasing, select MySQL for the source instance, Apsara PolarDB for the target instance, and One-way Synchronization for the synchronization topology.
  2. Log on to the Data Transmission Service console.
    Note

    If you are automatically redirected to the Data Management (DMS) console, you can click the jiqiren icon in the lower-right corner and then click 返回旧版 to return to the classic DTS console.

  3. In the navigation pane on the left, click Data Synchronization.
  4. In the top navigation bar of the Data Synchronization page, select the region where the destination instance is located.
  5. Find the purchased data synchronization instance and click Configure Synchronization Channel.
  6. Configure the source and destination instances.

    Category

    Parameter

    Description

    N/A

    Synchronization Task Name

    DTS generates a default name. Specify a descriptive name. Uniqueness is not required.

    Source Instance Details

    Instance Type

    Select RDS Instance.

    Instance Region

    The region of the source instance selected during DTS instance purchase. This value cannot be changed.

    Database Account

    Enter the database account of the source ApsaraDB RDS for MySQL instance.

    Note
    • The account must have REPLICATION CLIENT, REPLICATION SLAVE, SHOW VIEW, and SELECT permissions on all objects to synchronize.

    • For source RDS for MySQL instances running MySQL 5.5 or MySQL 5.6, the Database Account and Database Password parameters are not required.

    Database Password

    Enter the password of the database account.

    Connection Method

    Select Non-encrypted or SSL-encrypted. If you select SSL-encrypted, enable SSL encryption for the source ApsaraDB RDS for MySQL instance first. .

    Destination Instance Details

    Instance Type

    Set to PolarDB. This value cannot be changed.

    Instance Region

    The region of the destination instance selected during DTS instance purchase. This value cannot be changed.

    PolarDB Instance ID

    Select the cluster ID of the destination PolarDB for MySQL cluster.

    Database Account

    Enter the database account for the PolarDB for MySQL cluster.

    Note

    The account must have ALL permissions on the objects to synchronize.

    Database Password

    Enter the password for the database account.

  7. 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.

    Warning

    Adding 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.

  8. Configure the handling mode for existing tables in the destination database and select the synchronization objects.
    配置处理模式和同步对象
    Configuration Item Description
    Handling Mode for Existing Tables
    • Precheck and Report an Error: DTS checks whether a table with the same name exists in the destination database. If no table with the same name exists, the check passes. If a table with the same name exists, the precheck fails, and the data synchronization task does not start.
      Note If you cannot delete or rename the table in the destination database, you can use the object name mapping feature to avoid name conflicts. For more information, see Map object names in the destination instance.
    • Ignore Errors and Proceed: DTS skips the check for tables with the same name in the destination database.
      Warning If you select Ignore Errors and Proceed, data inconsistency may occur and pose risks to your business. For example:
      • If the table schemas are the same, records in the destination table with the same primary key value as in the source table are retained during the initial synchronization phase. During the incremental synchronization phase, these records are overwritten.
      • If the table schemas are different, data may fail to be initialized, only some columns may be synchronized, or the synchronization may fail.
    Select Synchronization Objects

    In the Source Objects box, click the object that you want to synchronize, and then click the 向右小箭头 icon to move it to the Selected Objects box.

    You can select databases and tables as synchronization objects.

    Note
    • If you select an entire database as a synchronization object, the schema changes of all objects in that database are synchronized to the destination database.
    • By default, the names of the synchronization objects are not changed. To change the name of an object in the destination cluster, use the object name mapping feature. For more information, see Map object names in the destination instance.
    Change Mapped Name

    Change the names of synchronized objects in the destination instance. For more information, see Map databases, tables, and columns.

    Replicate Temporary Tables to Destination Database During Online DDL in DMS

    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.

      Note

      If 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.

      Note

      This option causes tables in the destination database to be locked.

    Retry Duration for Unstable Connections

    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.

    Note

    You 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.

  9. After you complete the preceding configurations, click Next in the lower-right corner of the page.
  10. Configure advanced settings for initial synchronization.
    数据同步高级设置
    Note There are two types of initial synchronization: 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 historical data of the objects from the source database to the target database before the incremental data synchronization starts.
  11. After you complete the preceding configurations, click Precheck and Start in the lower-right corner of the page.

    Note
    • Before the synchronization task is officially started, a precheck is performed. The synchronization task can only be started after the precheck passes.

    • If the precheck fails, click the Prompt icon next to a specific check item to view the failure details.

      • Follow the prompt to fix the issue and run the precheck again.

      • If you do not need to fix the warning check items, you can also select Ignore, Ignore Warning Items and Rerun Precheck to skip the warning check items and run the precheck again.

  12. After Precheck Passed is displayed in the Precheck dialog box, close the dialog box. The synchronization task starts automatically.
  13. Wait until the synchronization channel is initialized and the task enters the Synchronizing state.
    The Data Synchronization page displays the status of data synchronization jobs.View sync job status