All Products
Search
Document Center

PolarDB:Synchronize data from a PolarDB for MySQL cluster to a self-managed Kafka cluster

Last Updated:Mar 30, 2026

Use Data Transmission Service (DTS) to stream row-level change events from a PolarDB for MySQL cluster to a self-managed Kafka cluster. This enables downstream systems to consume database changes in near real time for use cases such as log collection, data aggregation, stream processing, and online/offline analytics.

How it works

DTS reads the binary log (binlog) of your PolarDB for MySQL cluster and forwards row-level change events to the Kafka cluster you specify. Synchronization runs in three sequential phases:

  1. Initial schema synchronization — DTS copies the table schemas of the selected objects to the destination Kafka topic.

  2. Initial full data synchronization — DTS exports existing rows and writes them to Kafka.

  3. Incremental data synchronization — DTS continuously tails the binlog and forwards new change events in near real time.

Each source table maps to the Kafka topic you select during configuration. DTS does not automatically track table renames after the task starts.

Prerequisites

Before you begin, ensure that you have:

  • A Kafka cluster with a version between 0.10.1.0 and 2.7.0

  • Binary logging enabled for the PolarDB for MySQL cluster. See Enable binary loggingEnable binary logging

  • A database account on the source cluster with read permissions on the objects to be synchronized

  • Source tables with PRIMARY KEY or UNIQUE constraints and all fields unique — without these constraints, the destination may receive duplicate records

Limitations

  • Only tables can be selected as synchronization objects; database-level selection is not supported.

  • DTS does not automatically update the task when source tables are renamed. If a table is renamed during synchronization and the new name is not in the selected objects, DTS stops synchronizing that table's data. To resume, add the renamed table to the task's selected objects. See Add an object to a data synchronization task.

  • Ignore DDL in incremental synchronization phase is selected by default. DTS does not forward DDL operations from the source database during incremental synchronization.

Set up the synchronization task

Step 1: Purchase a DTS instance

Purchase a DTS instance. On the buy page, set:

  • Source Instance: PolarDB

  • Target Instance: Kafka

  • Synchronization Topology: One-Way Synchronization

Step 2: Open the DTS console

Log on to the DTS console.

If you are redirected to the Data Management (DMS) console, click the old icon in the image to switch to the previous version of the DTS console.

Step 3: Configure the synchronization task

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

  2. On the Synchronization Tasks page, select the region where the destination Kafka cluster resides.

  3. Find the instance you purchased and click Configure Task in the Actions column.

  4. Configure the source and destination instances.

    Configure the source and destination instances

    Source instance

    Parameter Description
    Instance type Set to PolarDB Instance (fixed).
    Instance region The source region selected on the buy page (read-only).
    PolarDB instance ID Select the PolarDB for MySQL cluster ID.
    Database account Enter the database account. The account must have read permissions on the objects to be synchronized.
    Database password Enter the password for the database account.

    Destination instance

    Parameter Description
    Instance type Select the deployment type of your Kafka cluster. This example uses User-Created Database in ECS Instance. For other instance types, configure the network environment first. See Preparation overview.
    Instance region The destination region selected on the buy page (read-only).
    ECS instance ID Select the Elastic Compute Service (ECS) instance where the Kafka cluster is deployed.
    Database type Select Kafka.
    Port number Enter the Kafka service port. The default port is 9092.
    Database account Enter the Kafka login username. Leave blank if the cluster has no authentication enabled.
    Database password Enter the Kafka password. Leave blank if the cluster has no authentication enabled.
    Topic Click Get Topic List and select a topic from the drop-down list.
    Kafka version Select the version of the destination Kafka cluster.
    Encryption Select Non-encrypted or SCRAM-SHA-256 based on your security requirements.

    Synchronization task name DTS generates a task name automatically. Specify a descriptive name for easy identification. The name does not need to be unique.

  5. Click Set Whitelist and Next.

    DTS adds its server CIDR blocks to the whitelist of the source PolarDB cluster and to the inbound rules of the destination ECS instance so that DTS servers can reach both endpoints.
  6. Select the objects to synchronize.

    Parameter Description
    Data format in Kafka Select Avro or Canal JSON. See Data formats of a Kafka cluster.
    Policy for shipping data to Kafka partitions Select the partition routing policy based on your workload. See Specify the policy for synchronizing data to Kafka partitions.
    Objects to be synchronized In the Available section, select one or more tables and click the Rightwards arrow icon to move them to the Selected section. DTS maps each table to the topic selected in the previous step. To change the topic a table maps to, use object name mapping. See Rename an object to be synchronized.
    Rename databases and tables Use object name mapping to rename objects at the destination. See Object name mapping.
    Retry time for failed connections Default is 720 minutes (12 hours). If DTS reconnects within this window, the task resumes automatically. Otherwise, the task fails. DTS charges apply during the retry period — set this value based on your requirements and release the DTS instance promptly if both source and destination instances are released.

    Select the objects to be synchronized

  7. Click Next.

  8. Configure initial synchronization.

    Parameter Description
    Initial synchronization Select both Initial Schema Synchronization and Initial Full Data Synchronization. DTS synchronizes schemas and historical data first, then switches to incremental synchronization.
    Filter options Ignore DDL in incremental synchronization phase is selected by default. DTS does not forward DDL operations from the source database during incremental synchronization.

    Kafka: Configure initial synchronization

  9. Click Precheck. DTS runs a precheck before the task starts. If any item fails, click the 提示 icon next to the failed item to view details. Fix the issues and run the precheck again. If an item does not affect your use case, ignore it and rerun the precheck.

  10. After the Precheck Passed message appears, close the dialog. The synchronization task starts automatically.

Monitor the task

View the task status on the Data Synchronization page.

View the status of a data synchronization task

What's next