You can use Data Transmission Service (DTS) to track data changes from databases in real time. You can use the change tracking feature in the following scenarios: lightweight cache updates, business decoupling and asynchronous data processing, and synchronization of extract, transform, and load (ETL) operations. This topic describes how to track data changes from an ApsaraDB RDS for MySQL instance.

Precautions

  • DTS does not track DDL operations that are performed by using gh-ost or pt-online-schema-change. Therefore, the change tracking client may fail to write the consumed data to the destination tables due to schema conflicts.
  • If the source database is involved in another task such as a running data migration task, DTS may track data changes of other objects. In this case, you must manually filter the tracked data on the change tracking client.

Procedure

  1. Create a change tracking instance. For more information, see Purchase a change tracking instance.
  2. Log on to the DTS console.
  3. In the left-side navigation pane, click Change Tracking.
  4. In the upper part of the Change Tracking Tasks page, select the region where the change tracking instance resides.
  5. Find the change tracking instance and click Configure Task in the Actions column.
  6. Configure the source database and network type for the change tracking task. Configure a change tracking task
    Section Parameter Description
    N/A Task Name The task name that DTS automatically generates. We recommend that you specify an descriptive name that makes it easy to identify the task. You do not need to use a unique task name.
    Source Database Instance Type The type of the source instance. In this example, RDS Instance is selected for this parameter.
    Note If your source database is a self-managed database, you must deploy the network environment for the database. For more information, see Preparation overview.
    Database Type The value of this parameter is set to MySQL and cannot be changed.
    Instance Region The source region that you selected on the buy page. The value of this parameter cannot be changed.
    RDS Instance ID The ID of the ApsaraDB RDS for MySQL instance from which you want to track data changes.
    Note A read-only instance or temporary instance cannot be used as the source instance for change tracking.
    Database Account The database account of the source ApsaraDB RDS for MySQL instance.
    Note
    • The account must have the SELECT permission on the required objects and the REPLICATION CLIENT, REPLICATION SLAVE, and SHOW VIEW permissions.
    • If the database engine of the source ApsaraDB RDS for MySQL instance is MySQL 5.5 or MySQL 5.6, you do not need to configure the database account or database password.
    Database Password The password for the account of the source ApsaraDB RDS for MySQL database.
    Network type
    • Classic
    • VPC

    The network type of the change tracking instance.

    Note
    • If your change tracking client is deployed on a local server, you can select Classic or VPC.
    • If your change tracking client is deployed on an ECS instance, we recommend that you select the network of the ECS instance. For example, if the ECS instance is deployed in a Virtual Private Cloud (VPC), select VPC as the network type and specify the VPC and vSwitch parameters.
    • If you track data changes over internal networks, the network latency is minimal.
    • Classic

      If you select Classic, no other configurations are required. For more information, see Network types.

    • VPC

      If you select VPC, you must specify the VPC and vSwitch parameters. For more information, see Network types.

  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Warning
    • If the source or destination database instance is an Alibaba Cloud database instance, such as an ApsaraDB RDS for MySQL or ApsaraDB for MongoDB instance, or is a self-managed database hosted on Elastic Compute Service (ECS), DTS automatically adds the CIDR blocks of DTS servers to the whitelist of the database instance or ECS security group rules. For more information, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases. If the source or destination database is a self-managed database on data centers or is from other cloud service providers, you must manually add the CIDR blocks of DTS servers to allow DTS to access the database.
    • If the CIDR blocks of DTS servers are automatically or manually added to the whitelist of the database instance or ECS security group rules, security risks may arise. Therefore, before you use DTS to migrate data, you must understand and acknowledge the potential risks and take preventive measures, including but not limited to the following measures: enhance the security of your account and password, limit the ports that are exposed, authenticate API calls, regularly check the whitelist or ECS security group rules and forbid unauthorized CIDR blocks, or connect the database to DTS by using Express Connect, VPN Gateway, or Smart Access Gateway.
    • After your DTS task is completed or released, we recommend that you manually detect and remove the added CIDR blocks from the whitelist of the database instance or ECS security group rules.
  8. In the Create Change Tracking Account message, wait until the account is created and then click Next.
    Note This step is required only if the database engine of the source ApsaraDB for MySQL instance is MySQL 5.5 or MySQL 5.6. In this step, DTS creates a database account for change tracking in the source instance.
  9. Select the data change types and objects. Select the data change types and objects
    Parameter Description
    Required Data Types
    • Data Updates

      DTS tracks data updates of the selected objects, including the INSERT, DELETE, and UPDATE operations.

    • Schema Updates

      DTS tracks the create, delete, and modify operations that are performed on all object schemas of the source instance. You must use the change tracking client to filter the required data.

    Note
    • If you select a database as the object, DTS tracks data changes of all objects, including new objects in the database.
    • If you select a table as the object, DTS tracks only data changes of this table. In this case, if you want to track data changes of another table, you must add the table to the selected objects. For more information, see Modify the objects for change tracking.
    Required Objects

    Select one or more objects from the Required Objects section and click the Rightwards arrow icon to add the objects to the Selected section.

    Note You can select tables or databases as the objects for change tracking.
  10. In the lower-right corner of the page, click Save and Precheck.
    Note
    • Before you can start the change tracking task, DTS performs a precheck. You can start the change tracking task only after the task passes the precheck.
    • If the task fails to pass the precheck, you can click the Info icon icon next to each failed item to view details. After you troubleshoot the issues based on the causes, you can run a precheck again.
  11. Close the Precheck dialog box after the following message is displayed: The precheck is passed.

After the change tracking task is configured, DTS performs initial change tracking, which takes about 1 minute. After initial change tracking is complete, you can create one or more consumer groups to consume the tracked data.

What to do next

  1. Create consumer groups
  2. Use a Kafka client to consume tracked data