Tablestore is a multi-model data storage service that is developed by Alibaba Cloud. It can store a large amount of structured data and supports fast query and analysis. This topic describes how to synchronize data from a user-created MySQL database or an ApsaraDB RDS for MySQL instance to a Tablestore instance by using Data Transmission Service (DTS).

Prerequisites

A Tablestore instance is created. For more information, see Create instances.

Precautions

  • DTS uses the read and write resources of the source and destination databases during initial full data synchronization. This may increase the loads of the database servers. Before you synchronize data, evaluate the impact of data synchronization on the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours.
  • DTS does not synchronize data definition language (DDL) operations. If a DDL operation is performed on a table in the source database during data synchronization, you must perform the following steps: Remove the table from the required objects, remove the table from the Tablestore instance, and then add the table to the required objects. For more information see Remove an object from a data synchronization task and Add an object to a data synchronization task.
  • You can synchronize at most 64 tables to the Tablestore instance. If you need to synchronize more than 64 tables to the Tablestore instance, submit a ticket to remove the limit.
  • The names of the tables or columns to be synchronized must comply with the naming conventions of the Tablestore instance.
    • The name of a table or index can contain letters, digits, and underscores (_). The name must start with a letter or underscore (_).
    • The name of a table or index must be 1 to 255 characters in length.

Initial synchronization types

Initial synchronization type Description
Initial schema synchronization DTS synchronizes the schemas of tables from the source database to the destination database.
Warning MySQL and Tablestore are heterogeneous databases. DTS does not ensure that the schemas of the source and destination databases are consistent after initial schema synchronization. We recommend that you evaluate the impact of data type conversion on your business. For more information, see Data type mappings for schema synchronization.
Initial full data synchronization DTS synchronizes historical data of tables from the source database to the destination database. Historical data is the basis for subsequent incremental data synchronization.
Initial incremental data synchronization DTS synchronizes incremental data from the source database to the destination database in real time.

The following SQL operations can be synchronized during initial incremental data synchronization: INSERT, UPDATE, and DELETE.

Warning Do not execute DDL statements in the source database. Otherwise, data synchronization may fail.

Before you begin

Notice When you configure the destination database, you must specify the AccessKey pair. To protect the AccessKey pair of your Alibaba Cloud account, we recommend that you grant permissions to a RAM user and create an AccessKey pair for the RAM user.
  1. Create a RAM user and grant the AliyunOTSFullAccess permission on Tablestore to the RAM user.
    1. Log on to the RAM console.
    2. Create a RAM user.
    3. In the left-side navigation pane, choose Identities > Users.
    4. On the Users page, find the RAM user, and click Add Permissions in the Actions column.
      Add permissions
    5. In the dialog box that appears, enter AliyunOTSFullAccess in the search box, and click the policy name to add the policy to the Selected section.
      Grant the AliyunOTSFullAccess permission
    6. Click OK.
    7. Click Finished.
  2. Create an AccessKey pair for the RAM user. For more information, see Create an AccessKey pair.
  3. Optional:If you need to configure a data synchronization task as a RAM user, you must grant the AliyunDTSDefaultRole permission to the RAM user. For more information, see Authorize DTS as a RAM user.
    Note If you use an Alibaba Cloud account to configure a data synchronization task, skip this step.

Procedure

  1. Purchase a data synchronization instance. For more information, see Purchase a DTS instance.
    Note On the buy page, set Source Instance to MySQL, set Target Instance to Tablestore, and set Synchronization Topology to One-Way Synchronization.
  2. Configure the source and destination databases.
    Configure the source and destination databases
    Section Parameter Description
    N/A Synchronization Task Name DTS automatically generates a task name. We recommend that you specify an informative name for easy identification. You do not need to use a unique task name.
    Source Instance Details Instance Type Select RDS Instance.
    Instance Region The source region that you selected on the buy page. You cannot change the value of this parameter.
    Instance ID Select the ID of the source RDS instance.
    Database Account Enter the database account of the source RDS instance. The account must have the SELECT permission on the required objects, the REPLICATION CLIENT permission, the REPLICATION SLAVE permission, and the SHOW VIEW permission.
    Note If the database engine of the source RDS instance is MySQL 5.5 or MySQL 5.6, you do not need to configure the database account or database password.
    Database Password Enter the password of the source database account.
    Encryption Select Non-encrypted or SSL-encrypted. If you want to select SSL-encrypted, you must enable SSL encryption for the RDS instance before you configure the data synchronization task. For more information, see Configure SSL encryption on an ApsaraDB RDS for MySQL instance.
    Notice The Encryption parameter is available only for regions in the Chinese mainland and the China (Hong Kong) region.
    Destination Instance Details Instance Type Select Tablestore.
    Instance Region The destination region that you selected on the buy page. You cannot change the value of this parameter.
    Instance ID Select the ID of the destination Tablestore instance.
    AccessKeyId Enter the AccessKey ID. For more information, see Create an AccessKey pair.
    AccessKeySecrect Enter the AccessKey secret.
  3. In the lower-right corner of the page, click Set Whitelist and Next.
    In this step, DTS adds the CIDR blocks of DTS servers to the whitelists of the source and destination instances. This ensures that DTS servers can connect to the source and destination instances.
  4. Configure the synchronization policy and the objects to be synchronized.
    1. Configure the synchronization policy.
      Configure the synchronization policy
      Parameter Description
      Initial Synchronization Select Initial Schema Synchronization, Initial Full Data Synchronization, and Initial Incremental Data Synchronization. For more information, see Initial synchronization types.
      Processing Mode In Existed Target Table
      Merge Multi Tables
      • Yes: In OLTP scenarios, sharding is implemented to speed up the response to business tables. You can merge multiple source tables that have the same schema into a single destination table. This feature allows you to synchronize data from multiple tables in the source database to a single table in the Tablestore instance.
        Note
        • DTS adds a column named __dts_data_source to the destination table in the Tablestore instance. This column is used to record the data source. The data type of this column is varchar. DTS specifies the column values based on the following format: <Data synchronization instance ID>:<Source database name>.<Source table name>. Such column values allow DTS to identify each source table. For example, dts********:dtstestdata.customer1 indicates that the source table is customer1.
        • If you set this parameter to Yes, all of the selected source tables in the task are merged into the destination table. If you do not need to merge specific source tables, you can create a separate data synchronization task for these tables.
      • No is selected by default.
      Synchronization Type Select the types of operations that you want to synchronize based on your business requirements. All operation types are selected by default.
    2. Select the objects to be synchronized.
      Select the objects to be synchronized
      Setting Description
      Select the objects to be synchronized Select one or more tables from the Available section and click the Right arrow icon to move the tables to the Selected section. Up to 64 tables can be migrated.

      After an object is synchronized to the destination instance, the name of the object remains unchanged. You can use the object name mapping feature to change the names of the objects that are synchronized to the destination instance. For more information, see Rename an object to be synchronized.

      Warning If you set Merge Multi Tables to Yes in Step 8 and select multiple source tables, you must use the object name mapping feature to change their names to the same table name in the Tablestore instance. Otherwise, data is inconsistent.
    3. Click Next.
  5. Optional:In the Selected section, move the pointer over a table, and then click Edit. In the Edit Table dialog box, set the data type of each column in the Tablestore instance.
    Set the data type
  6. Configure the primary key columns of the tables that you want to synchronize to the Tablestore instance.
    Advanced settings: Synchronize data from ApsaraDB RDS for MySQL to Tablestore
    Note For more information about primary keys of Tablestore instances, see Primary keys.