All Products
Search
Document Center

Data Transmission Service:Synchronize data from an RDS for MySQL instance to a Function Compute function

Last Updated:Apr 01, 2026

Data Transmission Service (DTS) can stream full or incremental data from an ApsaraDB RDS for MySQL instance to a Function Compute (FC) function. The function receives each change event in Canal Json format, so you can write function code to process inserts, updates, deletes, and DDL changes in real time.

Only Function Compute (FC) V2.0 is supported.

Prerequisites

Before you begin, ensure that you have:

  • An ApsaraDB RDS for MySQL instance as the source

  • A Function Compute service and function created, with Handler Type set to Event Handler — see Quickly create a function

  • Read permissions on the objects to be synchronized granted to the source database account

If the source database account was not created in the RDS for MySQL console, the account must have the REPLICATION CLIENT, REPLICATION SLAVE, SHOW VIEW, and SELECT permissions. To create and authorize an account, see Create an account and Modify account permissions.

Billing

Synchronization type Fee
Full data synchronization Free
Incremental data synchronization Charged. See Billing overview.

Supported SQL operations

Operation type SQL operations
DML INSERT, UPDATE, DELETE
DDL CREATE TABLE, ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE; CREATE/ALTER/DROP VIEW; CREATE/ALTER/DROP PROCEDURE; CREATE/DROP FUNCTION; CREATE/DROP TRIGGER; CREATE/DROP INDEX

Limitations

Source database requirements:

  • Tables must have primary keys or UNIQUE constraints, and all fields must be unique.

  • A single data entry cannot exceed 16 MB. Entries exceeding this limit cannot be written to the destination function and cause an error. Use the extract, transform, and load (ETL) feature to filter out large objects.

  • When selecting tables (not an entire database) as synchronization objects, a single task supports up to 1,000 tables. If this limit is exceeded, split the tables across multiple tasks or configure a task to synchronize the entire database.

  • Binary logging requirements:

    • ApsaraDB RDS for MySQL: Binary logging is enabled by default. Set the binlog_row_image parameter to full. For instructions, see Modify instance parameters.

    • Self-managed MySQL: Enable binary logging, set binlog_format to row, and set binlog_row_image to full. For a dual-primary cluster, also set log_slave_updates to ON. For instructions, see Create an account for a self-managed MySQL database and configure binary logging.

    • Binary log retention: Retain binary logs for at least 3 days on ApsaraDB RDS for MySQL (7 days recommended), and at least 7 days on self-managed MySQL. If the retention period is too short, the synchronization task may fail and data inconsistency or loss can occur. To set the retention period for ApsaraDB RDS for MySQL, see the Delete binary log files section.

  • Do not perform DDL operations to change database or table schemas during full data synchronization. DDL operations during this phase fail the task.

  • Data changes generated by physical backup restores or cascade operations are not recorded and are not synchronized to the destination.

    If such data is not synchronized, you can remove the affected databases and tables from the synchronization objects and then add them back, provided your business is not affected. See Modify the objects to be synchronized.
  • MySQL 8.0.23 and later: Invisible columns cannot be read, causing data loss. To make a column visible, run ALTER TABLE <table_name> ALTER COLUMN <column_name> SET VISIBLE;. See Invisible Columns. Tables without primary keys automatically generate invisible primary keys; make these visible before synchronizing. See Generated Invisible Primary Keys.

Other limitations:

  • Object mapping is not supported.

  • Cross-region data synchronization is not supported.

  • During full data synchronization, DTS uses read and write resources of the source and destination. Run full data synchronization during off-peak hours to reduce database load.

  • During full data synchronization, DTS performs concurrent INSERTs to the FC function. Make sure the function's instance concurrency is not set too low. See Configure instance concurrency.

  • If you select tables (not an entire database) as synchronization objects, do not use pt-online-schema-change for online DDL operations during synchronization. Use Data Management (DMS) instead. See Perform lock-free schema changes.

  • Do not synchronize multiple DTS tasks to the same destination function. Use separate functions for separate tasks to keep data isolated.

  • If the always-confidential (EncDB) feature is enabled on the RDS for MySQL instance, full data synchronization is not supported.

    If Transparent Data Encryption (TDE) is enabled instead of EncDB, full and incremental synchronization are both supported.
  • If a DTS task fails, DTS technical support will attempt to restore it within 8 hours. During restoration, the task may be restarted and task parameters may be modified. Database parameters are not modified. Parameters that may be modified are listed in Modify the parameters of a DTS instance.

Special cases:

  • Self-managed MySQL:

    • A primary/secondary switchover while the synchronization task is running causes the task to fail.

    • If no DML operations are performed on the source database for a long time, the reported synchronization latency may be inaccurate. Perform a DML operation on the source to refresh the latency. If you select an entire database as the synchronization object, create a heartbeat table that is updated every second.

    • DTS periodically executes CREATE DATABASE IF NOT EXISTS 'test' on the source to advance the binary log file position.

  • ApsaraDB RDS for MySQL:

    • A read-only ApsaraDB RDS for MySQL 5.6 instance that does not record transaction logs cannot be used as the source.

    • DTS periodically executes CREATE DATABASE IF NOT EXISTS 'test' on the source to advance the binary log file position.

Create a synchronization task

Step 1: Open the Data Synchronization page

Use one of the following methods:

DTS console

  1. Log on to the DTS console.DTS console

  2. In the left-side navigation pane, click Data Synchronization.

  3. In the upper-left corner, select the region where the synchronization task will reside.

DMS console

The exact navigation path may vary depending on your DMS console mode and layout. See Simple mode and Customize the layout and style of the DMS console.
  1. Log on to the DMS console.DMS console

  2. In the top navigation bar, move the pointer over Data + AI and choose DTS (DTS) > Data Synchronization.

  3. From the drop-down list next to Data Synchronization Tasks, select the region where the synchronization task will reside.

Step 2: Configure source and destination databases

  1. Click Create Task.

  2. Configure the following parameters.

Task-level settings:

Parameter Description
Task Name A name for the DTS task. DTS generates a name automatically. Specify a descriptive name to identify the task. The name does not need to be unique.

Source database settings:

Parameter Description
Select Existing Connection If the source instance is registered with DTS, select it from the drop-down list. DTS populates the connection parameters automatically. See Manage database connections. If not registered, configure the parameters below.
Database Type Select MySQL.
Access Method Select Alibaba Cloud Instance.
Instance Region Select the region where the source ApsaraDB RDS for MySQL instance resides.
Replicate Data Across Alibaba Cloud Accounts Select No for synchronization within the same Alibaba Cloud account.
RDS Instance ID Select the ID of the source ApsaraDB RDS for MySQL instance.
Database Account Enter the database account. For required permissions, see Prerequisites.
Database Password Enter the password for the database account.
Encryption Select Non-encrypted or SSL-encrypted. To use SSL encryption, enable SSL on the ApsaraDB RDS for MySQL instance first. See Use a cloud certificate to enable SSL encryption.

Destination database settings:

Parameter Description
Select Existing Connection If the destination function is registered with DTS, select it from the drop-down list. DTS populates the connection parameters automatically. See Manage database connections. If not registered, configure the parameters below.
Database Type Select Function Compute.
Access Method Select Alibaba Cloud Instance.
Instance Region Automatically set to the same region as the source. Cannot be changed.
Service Select the Function Compute service that contains the destination function.
Function Select the destination function that will receive the synchronized data.
Service Version and Alias Select one of the following options: Default Version (Service Version is fixed to LATEST), Specified Version (select a specific Service Version), or Specified Alias (select a specific Service Alias). For Function Compute terminology, see Basic Concepts.
  1. Click Test Connectivity and Proceed.

    DTS server CIDR blocks must be allowed in the security settings of your source and destination. DTS can add these automatically, or you can add them manually. See Add the CIDR blocks of DTS servers. If the source or destination is a self-managed database not using Alibaba Cloud Instance as the access method, click Test Connectivity in the CIDR Blocks of DTS Servers dialog box.

Step 3: Configure synchronization objects

In the Configure Objects step, configure the following settings:

Setting Description
Synchronization Types Incremental Data Synchronization is selected by default. Select Full Data Synchronization as well to synchronize existing data.
Data Format The format for data synchronized to the FC function. Only Canal Json is supported. For field descriptions and examples, see Canal Json format.
Source Objects Select databases or tables from the Source Objects section, then click the 向右 icon to move them to Selected Objects.
Selected Objects Review the selected objects. To remove an object, select it and click zuoyi.

Step 4: Configure advanced settings

Click Next: Advanced Settings and configure the following:

Setting Description
Dedicated Cluster for Task Scheduling By default, DTS schedules the task to the shared cluster. To improve synchronization stability, purchase a dedicated cluster. See What is a DTS dedicated cluster.
Retry Time for Failed Connections How long DTS retries after a connection failure. Valid values: 10–1440 minutes. Default: 720 minutes. Set this to more than 30 minutes. If DTS reconnects within this window, the task resumes; otherwise the task fails.
Note

When multiple tasks share the same source or destination database, the shortest retry time takes precedence. DTS charges for the instance during retry.

Retry Time for Other Issues How long DTS retries after DDL or DML operation failures. Valid values: 1–1440 minutes. Default: 10 minutes. Set this to more than 10 minutes.
Important

This value must be less than Retry Time for Failed Connections.

Enable Throttling for Full Data Synchronization Limits read/write load during full synchronization. Configure Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s). Only available when Full Data Synchronization is selected.
Enable Throttling for Incremental Data Synchronization Limits load during incremental synchronization. Configure RPS of Incremental Data Synchronization and Data synchronization speed for incremental synchronization (MB/s).
Whether to delete SQL operations on heartbeat tables of forward and reverse tasks Controls whether DTS writes heartbeat table operations to the source database. Yesalert notification settings: does not write heartbeat operations (the DTS instance may show a latency). No: writes heartbeat operations (may affect physical backup and cloning of the source database).
Environment Tag An optional tag to identify the task environment.
Configure ETL Whether to enable the extract, transform, and load (ETL) feature. Yes: enter data processing statements in the code editor. See Configure ETL in a data migration or data synchronization task. No: skip ETL configuration. For an overview, see What is ETL?
Monitoring and Alerting Whether to configure alerts. Yes: set an alert threshold and notification contacts. If the task fails or synchronization latency exceeds the threshold, contacts are notified. See Configure monitoring and alerting when you create a DTS task. No: alerting is disabled.

Step 5: Run the precheck and purchase an instance

  1. Click Next: Save Task Settings and Precheck. DTS runs a precheck before starting the synchronization task. If any item fails, click View Details to see the cause, fix the issue, and rerun the precheck. If an item shows an alert that can be ignored, click Confirm Alert Details, then Ignore > OK > Precheck Again. Ignoring alerts may cause data inconsistency.

    To preview the API parameters for this task, hover over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters before proceeding.
  2. When Success Rate reaches 100%, click Next: Purchase Instance.

  3. On the buy page, configure the following:

    Parameter Description
    Billing Method Subscription: pay upfront for a fixed period. More cost-effective for long-term use. Pay-as-you-go: billed hourly. Suitable for short-term use. Release the instance when no longer needed to avoid ongoing charges.
    Resource Group Settings The resource group for the synchronization instance. Default: default resource group. See What is Resource Management?
    Instance Class The synchronization speed varies by instance class. Select a class based on your requirements. See Instance classes of data synchronization instances.
    Subscription Duration Available only for the Subscription billing method. Options: 1–9 months, or 1, 2, 3, or 5 years.
  4. Read and select Data Transmission Service (Pay-as-you-go) Service Terms.

  5. Click Buy and Start, then click OK in the confirmation dialog box.

The task appears in the task list. You can monitor its progress there.

Data format received by the function

FC receives data as an Object. Incremental data arrives in the Records array, where each element is an Object representing one data record.

FC receives two types of events:

  • DML: data modification operations such as INSERT, UPDATE, and DELETE

  • DDL: schema changes such as ALTER TABLE

Event fields

Field Type Description
isDdl Boolean Whether the operation is a DDL operation. true: DDL. false: DML.
type String The SQL operation type. DML operations: DELETE, UPDATE, INSERT. DDL operations: fixed to DDL. During full data synchronization, fixed to INIT.
database String The name of the MySQL database.
table String The name of the MySQL table.
pkNames String The primary key name in the MySQL table.
es Long The execution time of the operation in the source database, as a 13-digit Unix timestamp in milliseconds.
ts Long The time when the operation started being written to the destination, as a 13-digit Unix timestamp in milliseconds.
data Object Array An array with one Object element. Keys are column names; values are the corresponding data values. For UPDATE operations, this contains the new values after the update.
old Object Array The data before an UPDATE, in the same format as data. This field only appears when type is UPDATE.
sql String Empty for DML operations. For DDL operations, contains the executed SQL statement.
id Int The serial number of the operation.

DDL event example

ALTER TABLE operation

SQL statement:

ALTER TABLE `demoTable`
    ADD COLUMN `address` varchar(20) NULL AFTER `sex`;

Data received by FC:

{
    "Records": [{
        "type": "DDL",
        "serverId": "27142679",
        "es": 1690000000000,
        "sql": "/* Query from DMS-WEBSQL-0-Eid_15682857722282385K by user 14xxxxxxxx */ ALTER TABLE `demoDatabase`.`DDL` \n\tADD COLUMN `address` varchar(20) NULL AFTER `sex`",
        "database": "demoDatabase",
        "id": 63151,
        "isDdl": true,
        "table": "demoTable",
        "ts": 1690000000000
    }]
}

isDdl is true and type is DDL. The sql field contains the executed DDL statement. data and old are absent for DDL events.

DML event examples

INSERT

SQL statement:

INSERT INTO demoTable VALUES("xiaoming", 10, "man");

Data received by FC:

{
    "Records": [{
        "data": [{
            "sex": "man",
            "name": "xiaoming",
            "age": "10"
        }],
        "pkNames": ["name"],
        "type": "INSERT",
        "serverId": "27142678",
        "es": 1690000000000,
        "sql": "",
        "database": "demoDatabase",
        "sqlType": {
            "sex": 253,
            "name": 253,
            "age": 3
        },
        "mysqlType": {
            "sex": "varchar",
            "name": "varchar",
            "age": "int"
        },
        "id": 62051,
        "isDdl": false,
        "table": "demoTable",
        "ts": 1690000000000
    }]
}

data contains the inserted row. type is INSERT and isDdl is false.

UPDATE

SQL statement:

UPDATE `demoDatabase`.`demoTable` SET `age`=11 WHERE `name`='xiaoming';

Data received by FC:

{
    "Records": [{
        "data": [{
            "sex": "man",
            "name": "xiaoming",
            "age": "11"
        }],
        "pkNames": ["name"],
        "old": [{
            "sex": "man",
            "name": "xiaoming",
            "age": "10"
        }],
        "type": "UPDATE",
        "serverId": "27142679",
        "es": 1690000000000,
        "sql": "",
        "database": "demoDatabase",
        "sqlType": {
            "sex": 253,
            "name": 253,
            "age": 3
        },
        "mysqlType": {
            "sex": "varchar",
            "name": "varchar",
            "age": "int"
        },
        "id": 62373,
        "isDdl": false,
        "table": "demoTable",
        "ts": 1690000000000
    }]
}

data contains the row after the update. old contains the row before the update. Compare the two to determine what changed.

DELETE

SQL statement:

DELETE FROM `demoDatabase`.`demoTable` WHERE `name`='xiaoming';

Data received by FC:

{
    "Records": [{
        "data": [{
            "sex": "man",
            "name": "xiaoming",
            "age": "11"
        }],
        "pkNames": ["name"],
        "type": "DELETE",
        "serverId": "27142679",
        "es": 1690000000000,
        "sql": "",
        "database": "demoDatabase",
        "sqlType": {
            "sex": 253,
            "name": 253,
            "age": 3
        },
        "mysqlType": {
            "sex": "varchar",
            "name": "varchar",
            "age": "int"
        },
        "id": 62635,
        "isDdl": false,
        "table": "demoTable",
        "ts": 1690000000000
    }]
}

data contains the deleted row's values at the time of deletion. old is absent for DELETE events.

What's next