This topic describes how to migrate data from an ApsaraDB RDS for MySQL instance to a Message Queue for Apache Kafka instance by using Data Transmission Service (DTS).

Prerequisites

  • The source ApsaraDB RDS for MySQL instance and the destination Message Queue for Apache Kafka instance are created.
    Note
  • The available storage space of the destination Message Queue for Apache Kafka instance is larger than the total size of the data in the source ApsaraDB RDS for MySQL instance.
  • In the destination Message Queue for Apache Kafka instance, a topic is created to receive the migrated data. For more information, see Step 1: Create a topic.

Precautions

Category Description
Limits on the source database
  • Bandwidth requirements: The server to which the source database belongs must have sufficient egress bandwidth. Otherwise, the data migration speed is affected.
  • The tables to be migrated must have PRIMARY KEY or UNIQUE constraints and all fields must be unique. Otherwise, the destination database may contain duplicate data records.
  • If you select tables as the objects to be migrated and you need to edit tables (such as renaming tables or columns), up to 1,000 tables can be migrated in a single data migration task. If you run a task to migrate more than 1,000 tables, a request error occurs. In this case, we recommend that you split the tables to be migrated, configure multiple tasks to migrate the tables, or configure a task to migrate the entire database.
  • If you need to migrate incremental data, you must make sure that the following requirements are met:
    • The binary logging feature must be enabled. The value of the binlog_format parameter must be set to row. The value of the binlog_row_image parameter must be set to full. Otherwise, error messages are returned during precheck and the data migration task cannot be started.
      Notice If the self-managed MySQL database is deployed in a dual-primary cluster), you must set the log_slave_updates parameter to ON. This setting ensures that DTS can obtain all binary logs.
    • If you perform only incremental data migration, the binary logs of the source database must be stored for more than 24 hours. If you perform both full data migration and incremental data migration, the binary logs of the source database must be stored for at least seven days. After full data migration is completed, you can set the retention period to more than 24 hours. Otherwise, DTS may fail to obtain the binary logs and the task may fail. In extreme cases, data may be inconsistent or lost. Make sure that you set the retention period of binary logs based on the preceding requirements. Otherwise, the Service Level Agreement (SLA) of DTS does not guarantee service reliability and performance.

  • Limits on operations:
    • During schema migration and full data migration, do not perform data definition language (DDL) operations to change the schemas of databases or tables. Otherwise, the data migration task fails.
    • If you perform only full data migration, do not write data to the source database during data migration. Otherwise, data will be inconsistent between the source and destination databases. To ensure data consistency, we recommend that you select Schema Migration, Full Data Migration, and Incremental Data Migration as the migration types.
Precautions
  • Before you configure a data migration task, you must create a Kafka cluster and the Kafka version must be 0.10.1.0 to 2.0.
  • You can select only tables as the objects to be migrated.
  • The service port of the Kafka cluster must be accessible over the Internet.
  • Before you migrate data, evaluate the impact of data migration on the performance of the source and destination databases. We recommend that you migrate data during off-peak hours. During full data migration, DTS uses read and write resources of the source and destination databases. This may increase the loads of the database servers.
  • During full data migration, concurrent INSERT operations cause fragmentation in the tables of the destination database. After full data migration is completed, the tablespace of the destination database is larger than that of the source database.
  • You must make sure that the precision settings for columns of the FLOAT or DOUBLE data type meets your business requirements. DTS uses the ROUND(COLUMN,PRECISION) function to retrieve values from columns of the FLOAT or DOUBLE data type. If you do not specify a precision, DTS sets the precision for the FLOAT data type to 38 digits and the precision for the DOUBLE data type to 308 digits.
  • DTS attempts to resume data migration tasks that failed within the last seven days. Before you switch workloads to the destination instance, stop or release the data migration task. You can also run the revoke command to revoke the write permissions from the accounts that are used by DTS to access the destination instance. Otherwise, the data in the source database will overwrite the data in the destination instance after the task is resumed.
  • We recommend that you do not use tools other than DTS to write data to the destination database. Otherwise, data will be inconsistent between the source and destination databases.
Special cases
If the source database is a self-managed MySQL database, take note of the following limits:
  • If you perform a primary/secondary switchover on the source database when the data migration task is running, the task fails.
  • DTS calculates migration latency based on the timestamp of the latest migrated data in the destination database and the current timestamp in the source database. If no data manipulation language (DML) operation is performed on the source database for a long time, the migration latency may be inaccurate. If the latency of the migration task is too high, you can perform a DML operation on the source database to update the latency.
    Note If you select an entire database as the object to be migrated, you can create a heartbeat table. The heartbeat table is updated or receives data every second.

Billing

Migration type Task configuration fee Internet traffic fee
Schema migration and full data migration Free of charge. Charged only when data is migrated from Alibaba Cloud over the Internet. For more information, see Pricing.
Incremental data migration Charged. For more information, see Pricing.

Migration types

SQL operations that can be migrated

Operation type SQL statements
DML INSERT, UPDATE, and DELETE
DDL
  • CREATE TABLE, ALTER TABLE, DROP TABLE, RENAME TABLE, and TRUNCATE TABLE
  • CREATE VIEW, ALTER VIEW, and DROP VIEW
  • CREATE PROCEDURE, ALTER PROCEDURE, and DROP PROCEDURE
  • CREATE FUNCTION, DROP FUNCTION, CREATE TRIGGER, and DROP TRIGGER
  • CREATE INDEX and DROP INDEX

Permissions required for database accounts

Database Schema migration Full data migration Incremental data migration
Source ApsaraDB RDS for MySQL instance The read permissions on the objects to migrate

Procedure

Note This procedure is described based on the new version of the DTS console. In the event of discrepancies in operations between the console and the DTS section in the Data Management Service (DMS) console, the DMS console takes precedence.

  1. Section Parameter Description
    None Task Name

    DTS automatically generates a task name. We recommend that you specify an informative name to identify the task. You do not need to use a unique task name.

    Source Database
    Database Type Select MySQL.
    Access Method Select Alibaba Cloud Instance.
    Instance Region Select the region in which the source ApsaraDB RDS for MySQL instance resides.
    Replicate Data Across Alibaba Cloud Accounts In this example, select No because data is replicated 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 of the source ApsaraDB RDS for MySQL instance. The account must have the read permissions on the objects to migrate.
    Database Password

    Enter the password of the database account.

    Encryption

    Select Non-encrypted or SSL-encrypted. If you want to select SSL-encrypted, you must enable SSL encryption for the ApsaraDB RDS for MySQL instance before you configure the data synchronization task. For more information, see Configure SSL encryption on an ApsaraDB RDS for MySQL instance.

    Destination Database
    Database Type Select Kafka.
    Access Method Select Express Connect, VPN Gateway, or Smart Access Gateway.
    Note You cannot select Message Queue for Apache Kafka as the instance type. You can use Message Queue for Apache Kafka as a self-managed Kafka database to configure data migration.
    Instance Region Select the region in which the destination Message Queue for Apache Kafka instance resides.
    Connected VPC Select the ID of the virtual private cloud (VPC) to which the destination Message Queue for Apache Kafka instance belongs. To obtain the VPC ID, you can log on to the Message Queue for Apache Kafka console and go to the Instance Details page of the Message Queue for Apache Kafka instance. On the Instance Details page, you can view the VPC ID.
    Hostname or IP address Enter an IP address that is included in the Default Endpoint parameter of the Message Queue for Apache Kafka instance.
    Note To obtain an IP address, you can log on to the Message Queue for Apache Kafka console and go to the Instance Details page of the Message Queue for Apache Kafka instance. On the Instance Details page, you can obtain an IP address from the Default Endpoint parameter.
    Port Number Enter the service port number of the Message Queue for Apache Kafka instance. The default port number is 9092.
    Database Account Enter the database account of the Message Queue for Apache Kafka instance.
    Note If the instance type of the Message Queue for Apache Kafka instance is VPC Instance, you do not need to specify the database account or database password.
    Database Password

    Enter the password of the database account.

    Kafka Version Select the version of the Message Queue for Apache Kafka instance.
    Encryption Select Non-encrypted or SCRAM-SHA-256 based on your business and security requirements.
    Topic Select a topic from the drop-down list.
    Topic That Stores DDL Information Select a topic from the drop-down list. The topic is used to store the DDL information. If you do not specify this parameter, the DDL information is stored in the topic that is specified by the Topic parameter.
    Use Kafka Schema Registry Kafka Schema Registry provides a serving layer for your metadata. It provides a RESTful API for storing and retrieving your Avro schemas.
    • No: Kafka Schema Registry is not used.
    • Yes: Kafka Schema Registry is used. In this case, you must enter the URL or IP address that is registered in Kafka Schema Registry for your Avro schemas.
  2. If a whitelist is configured for your self-managed database, you must add the CIDR blocks of DTS servers to the whitelist. Then, click Test Connectivity and Proceed.
    Note For more information about the CIDR blocks of DTS servers, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases.

    • Basic Settings
      Parameter Description
      Data Format in Kafka Select the format in which data is stored in the Message Queue for Apache Kafka instance.
      • If you select DTS Avro, data is parsed based on the schema definition of DTS Avro. For more information, visit GitHub.
      • If you select Canal Json, data is stored in the Canal JSON format. For more information about the related parameters and examples, see the Canal JSON section in Data formats of a Kafka cluster.
      Policy for Shipping Data to Kafka Partitions Select a migration policy based on your business requirements. For more information, see Specify the policy for migrating data to Kafka partitions.
      Note You can select only databases as the objects to migrate.
      In the Selected Objects section, right-click an object. In the dialog box that appears, select the DDL and DML operations that you want to migrate. For more information about the SQL operations that can be migrated, see SQL operations that can be migrated.
    • Advanced Settings
      Parameter Description
      Capitalization of Object Names in Destination Instance Specify the capitalization of database names, table names, and column names in the destination instance. By default, DTS default policy is selected. You can select other options to make sure that the capitalization of object names is consistent with that of the source or destination database. For more information, see Specify the capitalization of object names in the destination instance.