All Products
Search
Document Center

ApsaraDB for SelectDB:Use SeaTunnel to import data

Last Updated:Mar 28, 2026

ApsaraDB for SelectDB integrates with SeaTunnel, letting you sync data from upstream sources such as MySQL, Hive, and Kafka directly into ApsaraDB for SelectDB using the SelectDB Sink connector.

How it works

SeaTunnel reads data from a source connector, serializes it as JSON or CSV, and writes it to ApsaraDB for SelectDB through the SelectDB Sink. The sink buffers records in memory and flushes them to Object Storage Service (OSS) when the buffer limit is reached. With two-phase commit (2PC) enabled (the default), the sink guarantees exactly-once semantics.

Prerequisites

Before you begin, make sure you have:

  • SeaTunnel 2.3.1 or later installed

  • An ApsaraDB for SelectDB instance with a cluster configured

  • Network access from your SeaTunnel host to the ApsaraDB for SelectDB instance (VPC or public endpoint)

Sink configuration

All sink configurations use the SelectDB (or SelectDBCloud) block. The required parameters and the selectdb.config block differ depending on the data format.

JSON format

sink {
  SelectDB {
    load-url="<host>:<http_port>"
    jdbc-url="<host>:<mysql_port>"
    cluster-name="<cluster_name>"
    table.identifier="<db_name>.<table_name>"
    username="<username>"
    password="<password>"
    selectdb.config {
      file.type="json"
      file.strip_outer_array="false"
    }
  }
}

CSV format

sink {
  SelectDB {
    load-url="<host>:<http_port>"
    jdbc-url="<host>:<mysql_port>"
    cluster-name="<cluster_name>"
    table.identifier="<db_name>.<table_name>"
    username="<username>"
    password="<password>"
    selectdb.config {
      file.type="csv"
      file.column_separator=","
      file.line_delimiter="\n"
    }
  }
}

Parameters

ParameterRequiredDescription
load-urlYesThe HTTP endpoint of the ApsaraDB for SelectDB instance, in the format <host>:<http_port>. On the Instance Details page, go to Network Information and combine the VPC Endpoint or Public Endpoint with the HTTP Port. Example: selectdb-cn-4xl3jv1****.selectdbfe.rds.aliyuncs.com:8080
jdbc-urlYesThe MySQL endpoint of the ApsaraDB for SelectDB instance, in the format <host>:<mysql_port>. On the same page, combine the VPC Endpoint or Public Endpoint with the MySQL Port. Example: selectdb-cn-4xl3jv1****.selectdbfe.rds.aliyuncs.com:9030
cluster-nameYesThe name of the target cluster within the instance. An instance can contain multiple clusters.
usernameYesThe username used to connect to the instance.
passwordYesThe password used to connect to the instance.
table.identifierYesThe target table, in the format <database_name>.<table_name>. Example: test_db.test_table
selectdb.configYesData format settings. See the JSON and CSV examples above.
sink.enable-deleteNoEnables bulk deletion. Only supported for the unique key model.
sink.buffer-sizeNoMaximum buffer size in bytes. Default: 10 MB. When the buffer is full, its contents are flushed to OSS. We recommend that you use the default value.
sink.buffer-countNoMaximum number of records held in the buffer. Default: 10,000. When exceeded, the buffer is flushed to OSS. We recommend that you use the default value.
sink.max-retriesNoMaximum number of retries during the commit phase. Default: 3.
sink.enable-2pcNoEnables two-phase commit to guarantee exactly-once semantics. Default: true.

Example: sync data from MySQL to ApsaraDB for SelectDB

This example walks through syncing an employees table from a MySQL database to ApsaraDB for SelectDB using the SeaTunnel local engine in batch mode.

Environment versions used in this example:

ComponentVersion
Java Development Kit (JDK)1.8
SeaTunnel2.3.3
ApsaraDB for SelectDB3.0.4

Step 1: Set up SeaTunnel

  1. Download and extract the SeaTunnel installation package.

    wget https://dlcdn.apache.org/seatunnel/2.3.3/apache-seatunnel-2.3.3-bin.tar.gz
    tar -xzvf apache-seatunnel-2.3.3-bin.tar.gz
  2. Edit $SEATUNNEL_HOME/config/plugin_config to include only the connectors needed for this example.

    --connectors-v2--
    connector-cdc-mysql
    connector-selectdb-cloud
    connector-jdbc
    connector-fake
    connector-console
    connector-assert
    --end--
  3. Install the connector plugins.

    sh bin/install-plugin.sh
  4. Download the MySQL JDBC driver and place it in the lib/ directory.

    cd lib/
    wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28.jar

Step 2: Prepare the source data in MySQL

  1. Create the source table in your MySQL database.

    CREATE TABLE `employees` (
      `emp_no`     INT          NOT NULL,
      `birth_date` DATE         NOT NULL,
      `first_name` VARCHAR(14)  NOT NULL,
      `last_name`  VARCHAR(16)  NOT NULL,
      `gender`     ENUM('M','F') NOT NULL,
      `hire_date`  DATE         NOT NULL,
      PRIMARY KEY (`emp_no`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
  2. Populate the table with test data. You can use Data Management (DMS) to generate test data.

Step 3: Configure ApsaraDB for SelectDB

  1. Create an ApsaraDB for SelectDB instance.

  2. Connect to the instance over the MySQL protocol, then create the target database and table.

    CREATE DATABASE test_db;
    
    USE test_db;
    CREATE TABLE employees (
        emp_no     INT NOT NULL,
        birth_date DATE,
        first_name VARCHAR(20),
        last_name  VARCHAR(20),
        gender     CHAR(2),
        hire_date  DATE
    )
    UNIQUE KEY(`emp_no`)
    DISTRIBUTED BY HASH(`emp_no`) BUCKETS 1;
  3. Apply for a public endpoint so SeaTunnel can reach the instance over the internet.

  4. Add the public IP address of your SeaTunnel host to the IP address whitelist of the instance.

Step 4: Run the sync job

  1. Create the job configuration file mysqlToSelectDB.conf.

    env {
      execution.parallelism = 2
      job.mode = "BATCH"
      checkpoint.interval = 10000
    }
    
    source {
      jdbc {
        url = "jdbc:mysql://<mysql_host>:<mysql_port>/test_db"
        driver = "com.mysql.cj.jdbc.Driver"
        user = "<mysql_username>"
        password = "<mysql_password>"
        query = "select * from employees"
      }
    }
    
    sink {
      SelectDBCloud {
        load-url="selectdb-cn-pe33hab****-public.selectdbfe.rds.aliyuncs.com:8080"
        jdbc-url="selectdb-cn-pe33hab****-public.selectdbfe.rds.aliyuncs.com:9030"
        cluster-name="new_cluster"
        table.identifier="test_db.employees"
        username="<selectdb_username>"
        password="<selectdb_password>"
        selectdb.config {
          file.type="json"
        }
      }
    }

    Replace the placeholder values with your actual connection details. The load-url and jdbc-url values are available on the Instance Details page under Network Information.

  2. Submit the job.

    sh ./bin/seatunnel.sh --config ./mysqlToSelectDB.conf -e local

    After the job completes, query the test_db.employees table in ApsaraDB for SelectDB to verify that the data was imported successfully.

What's next