Tablestore is a multi-model data storage service that is developed by Alibaba Cloud. Tablestore can store large volumes of structured data by using multiple models, and supports fast data query and analytics. This topic describes how to synchronize data from an ApsaraDB RDS for MySQL instance to a Tablestore instance by using Data Transmission Service (DTS). You can also follow the procedure to synchronize data from a self-managed MySQL database to a Tablestore instance. The data synchronization feature allows you to transfer and analyze data with ease.

Prerequisites

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

Precautions

  • During initial full data synchronization, DTS consumes the read and write resources of the source and destination databases. 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 selected objects, remove the table from the Tablestore instance, and then add the table to the selected objects again. 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 raise the limit.
  • The names of the tables and columns to be synchronized must comply with the naming conventions of the Tablestore instance.
    • The name of a table or an index can contain letters, digits, and underscores (_). The name must start with a letter or underscore (_).
    • The name of a table or an 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 We recommend that you 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 Complete.
  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 to access Alibaba Cloud resources.
    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 Destination Instance to Tablestore, and set Synchronization Topology to One-way Synchronization.
  2. Log on to the DTS console.
  3. In the left-side navigation pane, click Data Synchronization.
  4. In the upper part of the Synchronization Tasks page, select the region where the destination instance resides.
  5. Find the data synchronization instance and click Configure Task in the Actions column.
  6. 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 to identify the task. 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 objects to be synchronized, 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 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 for 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.
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note
    • You do not need to modify the security settings for ApsaraDB instances (such as ApsaraDB RDS for MySQL and ApsaraDB for MongoDB) and ECS-hosted databases. DTS automatically adds the CIDR blocks of DTS servers to the whitelists of ApsaraDB instances or the security group rules of Elastic Compute Service (ECS) instances. For more information, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases.
    • After data synchronization is complete, we recommend that you remove the CIDR blocks of DTS servers from the whitelists or security groups.
  8. 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 Destination Table
      • Pre-check and Intercept: checks whether the destination database contains tables that have the same names as tables in the source database. If the destination database does not contain tables that have the same names as tables in the source database, the precheck is passed. Otherwise, an error is returned during precheck and the data synchronization task cannot be started.
        Note You can use the object name mapping feature to rename the tables that are synchronized to the destination database. You can use this feature if the source and destination databases contain identical table names and the tables in the destination database cannot be deleted or renamed. For more information, see Rename an object to be synchronized.
      • Ignore: skips the precheck for identical table names in the source and destination databases.
        Warning If you select Ignore, data consistency is not guaranteed and your business may be exposed to potential risks.
        • During initial data synchronization, DTS does not synchronize the data records that have the same primary keys as the data records in the destination database. This occurs if the source and destination databases have the same schema. However, DTS synchronizes these data records during incremental data synchronization.
        • If the source and destination databases have different schemas, initial data synchronization may fail. In this case, only some columns are synchronized or the data synchronization task fails.
      Merge Multi Tables
      • Yes: In online transaction processing (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.
      Processing Policy of Dirty Data Select a processing policy for handling data write errors:
      • Skip
      • Block
      Data Write Mode
      • Update Row: The PutRowChange operation is performed to update rows in the Tablestore instance.
      • Overwrite Row: The UpdateRowChange operation is performed to overwrite rows in the Tablestore instance.
      Batch Write Operation Select the operation used to write multiple rows of data to the Tablestore instance.
      • BulkImportRequest: Data is written offline.
      • BatchWriteRowRequest: Data is written in batches.
      To achieve higher read and write efficiency and reduce your costs of using the Tablestore instance, we recommend that you select BulkImportRequest.
      More
      └ Queue Size Enter the length of the queue for writing data to the Tablestore instance.
      └ Thread Quantity Enter the number of callback threads for writing data to the Tablestore instance.
      └ Concurrency Enter the maximum number of concurrent threads for the Tablestore instance.
      └ Buckets Enter the number of concurrent buckets for incremental and sequential writes. To improve the concurrent write capability, you can set this parameter to a relatively larger value.
      Note The value must be less than or equal to the maximum number of concurrent threads.
    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 Rightwards arrow icon to move the tables to the Selected section. Up to 64 tables can be selected.

      By default, 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 rename 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.
  9. 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
  10. 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.
  11. In the lower-right corner of the page, click Next: Precheck and Start Task.
    Note
    • Before you can start the data synchronization task, DTS performs a precheck. You can start the data synchronization 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.
  12. Close the Precheck dialog box after the following message is displayed: The precheck is passed. Then, the data synchronization task starts.
  13. Wait until initial synchronization is complete and the data synchronization task enters the Synchronizing state.
    You can view the state of the data synchronization task on the Synchronization Tasks page. View the state of a data synchronization task