Migrate data from a TiDB database to a MySQL tenant of OceanBase Database

更新时间:
复制 MD 格式

This topic describes how to use the data transmission service to migrate data from a TiDB database to a MySQL tenant of OceanBase Database.

Important

If a data migration task remains inactive for an extended period (with a status of Failed, Paused, or Completed), it may not be resumable due to factors such as the retention period of incremental logs. To reclaim resources, Data Transmission Service releases data migration tasks that have been inactive for more than three days. We recommend that you configure alerts for your tasks and handle any exceptions promptly.

Background

The data transmission service allows you to seamlessly migrate the existing business data and incremental data from a TiDB database to a MySQL tenant of OceanBase Database through schema migration, full migration, and incremental synchronization.

TiDB is an integrated distributed database that supports hybrid transactional and analytical processing (HTAP). You must deploy a TiCDC cluster and a Kafka cluster to synchronize incremental data from a TiDB database to a MySQL tenant of OceanBase Database.

image.png

TiCDC is an incremental data synchronization tool for TiDB and provides high availability by using a placement driver (PD) cluster, which is the scheduling module of the TiDB cluster and usually consists of three PD nodes. TiKV Server is a TiKV node in the TiDB cluster. It sends data changes in change logs to the TiCDC cluster. TiCDC runs multiple TiCDC processes to obtain and process data from TiKV nodes, and then synchronizes the data to the Kafka cluster. The Kafka cluster saves the incremental logs of the TiDB database that are converted by TiCDC. During incremental data synchronization, the data transmission service obtains the corresponding data from the Kafka cluster and migrates the data to the MySQL tenant of OceanBase Database in real time.

If you create a TiDB data source without binding it to a Kafka data source, you cannot perform incremental synchronization.

Prerequisites

  • The data transmission service has the privilege to access cloud resources. For more information, see Role authorization for data transmission and migration.

  • You have created dedicated database users for data migration in the source TiDB database and target MySQL tenant of OceanBase Database, and granted corresponding privileges to the users. For more information, see Create a database user.

Limitations

  • Limitations on the source database

    Do not perform DDL operations that modify database or table schemas during schema migration or full migration. Otherwise, the data migration task may be interrupted.

  • Only TiDB 4.x and 5.x are supported.

  • The data transmission service does not support DDL synchronization for data migration from a TiDB database to a MySQL tenant of OceanBase Database.

  • The data transmission service does not support triggers in the target database. If triggers exist in the target database, the data migration may fail.

  • The data transmission service does not support the migration of tables without primary keys and data with spaces from a TiDB database to a MySQL tenant of OceanBase Database.

  • Data source identifiers and user accounts must be globally unique in the data transmission system.

  • The data transmission service supports the migration of an object only when the following conditions are met: the database name, table name, and column name of the object are ASCII-encoded without special characters. The special characters are line breaks, spaces, and the following characters: . | " ' ` ( ) = ; / & \.

  • The data transmission service supports only the TiCDC Open Protocol. If you use an unsupported protocol, a null pointer error is returned.

  • When you use TiCDC to synchronize data to a Kafka instance, you must add the enable-old-value = true setting to the configuration file. Otherwise, the formats of data synchronization messages may be invalid. For more information, see Task configuration file.

Considerations

  • If the source contains foreign keys with the same name, an error occurs during schema migration. In this case, you can rename the foreign keys to restore the task.

  • If the UTF-8 character set is used in the source database, we recommend that you use a compatible character set, such as UTF-8 or UTF-16, in the target database to avoid garbled characters.

  • Do not write data to the topic synchronously used by TiCDC. Otherwise, a null pointer error is returned.

  • Check whether the migration precision of the data transmission service for columns of data types such as DECIMAL, FLOAT, and DOUBLE is as expected. If the precision of the target field type is lower than that of the source field type, the value with a higher precision may be truncated. This may result in data inconsistency between the source and target fields.

  • If you modify a unique index at the target, you must restart the data migration task to avoid data inconsistency.

  • If the clocks between nodes or between the client and the server are out of synchronization, the latency may be inaccurate during incremental synchronization or reverse incremental synchronization.

    For example, if the clock is earlier than the standard time, the latency can be negative. If the clock is later than the standard time, the latency can be positive.

  • Take note of the following considerations if you want to aggregate multiple tables:

    • We recommend that you configure the mappings between the source and target databases by specifying matching rules.

    • We recommend that you manually create schemas at the target. If you create schemas at the target by using the data transmission service, skip the failed objects in the schema migration step.

  • A difference between the source and target table schemas may result in data consistency. Some known scenarios are described as follows:

    • When you manually create a table schema in the target, if the data type of any column is not supported by the data transmission service, implicit data type conversion may occur in the target, which causes inconsistent column types between the source and target databases.

    • If the length of a column at the target is shorter than that in the source database, the data of this column may be automatically truncated, which causes data inconsistency between the source and target databases.

  • If you selected only Incremental Synchronization when you created the data migration task, the data transmission service requires that the local incremental logs of the source database be retained for at least 48 hours.

    If you selected Full Migration and Incremental Synchronization when you created the data migration task, the data transmission service requires that the local incremental logs of the source database be retained for at least 7 days. If the data transmission service cannot obtain incremental logs, the data migration task may fail or even the data between the source and target databases may be inconsistent after migration.

  • If the source or target database contains table objects that differ only in letter cases, the data migration results may not be as expected due to case insensitivity in the source or target database.

Supported source and target instance types

In the following table, OB_MySQL stands for the MySQL tenant of OceanBase Database.

Source

Target

TiDB (self-managed database in a VPC)

OB_MySQL (OceanBase cluster instance)

TiDB (self-managed database with a public IP address)

OB_MySQL (OceanBase cluster instance)

TiDB (self-managed database in a VPC)

OB_MySQL (serverless instance)

TiDB (self-managed database with a public IP address)

OB_MySQL (serverless instance)

Data type mappings

TiDB database

MySQL tenant of OceanBase Database

INTEGER

INTEGER

TYNYINT

TYNYINT

MEDIUMINT

MEDIUMINT

BIGINT

BIGINT

SMALLINT

SMALLINT

DECIMAL

DECIMAL

NUMERIC

NUMERIC

FLOAT

FLOAT

REAL

REAL

DOUBLE PRECISION

DOUBLE PRECISION

BIT

BIT

CHAR

CHAR

VARCHAR

VARCHAR

BINARY

BINARY

VARBINARY

VARBINARY

BLOB

BLOB

TEXT

TEXT

ENUM

ENUM

SET

SET

DATE

DATE

DATETIME

DATETIME

TIMESTAMP

TIMESTAMP

TIME

TIME

YEAR

YEAR

Procedure

  1. Log on to the OceanBase Management Console and purchase a data migration task.

    For more information, see Purchase a data migration task.

  2. On the Data Transmission > Data Migration page, click Configure for your new data migration task.

    image.png

    To reference an existing task configuration, you can click Reference Configuration. For more information, see Reference a data migration task configuration.

  3. On the Select Source and Target page, configure the related parameters.

    Parameter

    Description

    Migration Task Name

    We recommend that you set it to a combination of digits and letters. It must not contain any spaces and cannot exceed 64 characters in length.

    Source

    If you have created a TiDB data source, select it from the drop-down list. Otherwise, click New Data Source in the drop-down list and create one in the dialog box that appears on the right. For more information, see Create a TiDB data source.

    Target

    If you have created a data source for the MySQL tenant of OceanBase Database, select it from the drop-down list. Otherwise, click New Data Source in the drop-down list and create one in the dialog box that appears on the right. For more information about the parameters, see Create an OceanBase data source.

    Tag (Optional)

    Select a target tag from the drop-down list. You can also click Manage Tags to create, modify, and delete tags. For more information, see Manage data migration tasks with tags.

  4. Click Next. On the Select Migration Type page, specify migration types for the current data migration task.

    Supported migration types are schema migration, full migration, incremental synchronization, full verification, and reverse incremental synchronization.

    image

    Migration type

    Description

    Schema migration

    After a schema migration task is started, the data transmission service migrates the definitions of database objects (such as tables, indexes, constraints, comments, and views) from the source database to the target database and automatically filters out temporary tables.

    Full migration

    After a full migration task is started, the data transmission service migrates existing data from tables in the source database to corresponding tables in the target database. If you select Full Migration, we recommend that you use the ANALYZE statement to collect the statistics of the TiDB database before data migration.

    Incremental synchronization

    After an incremental synchronization task is started, the data transmission service synchronizes changed data (data that is added, modified, or removed) from the source database to corresponding tables in the target database.

    DML Synchronization is supported for Incremental Synchronization. You can select operations as needed. For more information, see Configure DDL/DML synchronization. If you create a TiDB data source without binding it to a Kafka data source, you cannot select Incremental Synchronization.

    Full verification

    After the full migration and incremental synchronization tasks are completed, the data transmission service automatically initiates a full verification task to verify the tables in the source and target databases.

    • If you select Full Verification, we recommend that you collect the statistics of the TiDB database and the MySQL tenant of OceanBase Database before full verification.

    • If you select Incremental Synchronization but do not select all DML statements in the DML Synchronization section, you cannot select Full Verification.

    Reverse incremental synchronization

    Data changes made in the target database after the business database switchover are synchronized to the source database in real time through reverse incremental synchronization.

    Generally, incremental synchronization configurations are reused for reverse incremental synchronization. You can also customize the configurations for reverse incremental synchronization as needed.

  5. Click Next. On the Select Migration Objects page, specify migration objects for the data migration task.

    You can select Specify Objects or Match Rules to specify the migration objects. This topic describes how to specify the migration objects by using Specify Objects. For information about matching rules, see Configure and modify matching rules.

    Important
    • The names of tables to be migrated, as well as the names of columns in the tables, must not contain Chinese characters.

    • If a database or table name contains double dollar signs ($$), you cannot create the migration task.

    image.png

    1. In the Select Migration Objects section, select Specify Objects.

    2. In the Source Object(s) list of the Specify Migration Scope section, select the objects to migrate. You can select tables and views of one or more databases.

    3. Click > to add them to the Target Object(s) list.

    Data Transmission Service lets you import objects from text files. It also lets you rename destination objects, set row filters, view column information, and remove a single object or all objects.

    Note

    When you select migration objects using the Matching Rules method, the matching rule syntax overrides the renaming capability, and the Actions section is limited to setting filter conditions. For more information, see Configure and modify matching rules.

    Operation

    Description

    Import Object

    1. In the list on the right of the selection area, click Import Object in the upper-right corner.

    2. In the dialog box that appears, click OK.

      Important

      The import operation overwrites previous selections. Proceed with caution.

    3. In the Import Migration Objects dialog box, import the objects to be migrated.

      You can import a CSV file to rename database tables, set row filtering conditions, and perform other operations. For more information, see Download and import migration object configurations.

    4. Click Check Validity.

      After you import the migration objects, check their validity first. Column field mapping is not currently supported.

    5. After the check is passed, click OK.

    Rename

    Data Transmission Service lets you rename migration objects. For more information, see Rename database and table objects.

    Settings

    Data Transmission Service supports row filtering using WHERE conditions. For more information, see Filter data with SQL conditions.

    You can also view the column information of migration objects in the View Columns area.

    Remove/Remove All

    Data Transmission Service lets you remove one or more objects that have been temporarily selected for the destination during data mapping.

    • Remove a single migration object

      In the list on the right of the selection area, hover over the target object and click the displayed Remove button to remove the migration object.

    • Remove all migration objects

      In the list on the right of the selection area, click Remove All in the upper-right corner. In the dialog box that appears, click OK to remove all migration objects.

  6. Click Next. On the Migration Options page, configure the parameters.

    • Full migration

      The following parameters are displayed only if you select Full Migration on the Select Migration Types page.

      image

      Parameter

      Description

      Read Concurrency

      This parameter specifies the number of concurrent threads for reading data from the source during full migration. The maximum value is 512. A high degree of concurrency may put excessive pressure on the source database and affect your business.

      Write Concurrency

      This parameter specifies the number of concurrent threads for writing data to the destination during full migration. The maximum value is 512. A high degree of concurrency may put excessive pressure on the destination database and affect your business.

      Full Migration Rate Limit

      You can enable the full migration rate limit as needed. If you enable it, set the RPS (maximum number of data rows that can be migrated to the destination per second during full migration) and BPS (maximum volume of data that can be migrated to the destination per second during full migration).

      Note

      The RPS and BPS settings only serve as throttling limits. The actual performance of full migration is affected by factors such as the source, destination, and instance specifications.

      Policy for Existing Records in Destination Table Objects

      The policies include Ignore and Stop Migration:

      • Select Ignore: If data exists in the destination table object and a conflict occurs between the original data and the data to be written, DTS logs the conflicting data and keeps the original data unchanged.

        Important

        If you select Ignore, full verification uses the IN mode to pull data. It cannot verify scenarios where the destination has data that the source does not. The verification performance is also degraded to some extent.

      • Select the default value Stop Migration: If data exists in the destination table object, full migration reports an error and is not allowed. Handle the data in the destination and then continue the migration.

        Important

        If you click Resume after an error occurs, DTS ignores this setting and continues to migrate table data. Proceed with caution.

      Allow index suffixes

      You can specify whether to allow index creation after full data migration is complete. This feature can shorten the time required for full migration. For notes on post-migration index creation, see the description below the table.

      Important
      • This parameter is displayed only if you select both Schema Migration and Full Migration on the Select Migration Types page.

      • Only non-unique key indexes support post-migration creation.

      • When an index is being created, if the destination OceanBase database reports one of the following errors, DTS ignores the error and considers the index successfully created. It will not attempt to create the index again.

        • The OceanBase database MySQL tenant reports a Duplicate key name error.

        • The OceanBase database Oracle tenant reports a name is already used by an existing object error.

      If the destination is an OceanBase database and you select Allow, configure the following parameters:

      • Concurrency for a single index DDL statement: A higher degree of parallelism consumes more resources and increases the migration speed.

      • Maximum number of concurrent index DDL statements: The maximum number of post-migration index DDL statements that the system can invoke at the same time.

      If you allow post-migration index creation, we recommend that you use a command-line client to adjust the following business tenant parameters based on the hardware and service traffic of the OceanBase database.

      // File memory buffer limit
      alter system set _temporary_file_io_area_size = '10' tenant = 'xxx'; 
      // V4.x disable throttling
      alter system set sys_bkgd_net_percentage = 100;  
    • Incremental synchronization

      The following parameters appear only if you select Incremental Synchronization on the Select Migration Types page.

      image

      Parameter

      Description

      Write Concurrency

      This parameter specifies the number of concurrent threads for writing data to the destination during incremental synchronization. The maximum value is 512. A high degree of concurrency may put excessive pressure on the destination and affect your services.

      Incremental Synchronization Rate Limit

      You can decide whether to enable the incremental synchronization rate limit as needed. If you enable it, set RPS (the maximum number of data rows that can be synchronized to the destination per second during incremental synchronization) and BPS (the maximum volume of data that can be synchronized to the destination per second during incremental synchronization).

      Note

      The RPS and BPS settings here only serve as a rate-limiting capability. The actual performance of incremental synchronization is affected by factors such as the source, destination, and instance specifications.

      Incremental Synchronization Start Offset

      • If you select Full Migration, this parameter is not displayed.

      • If you select Incremental Synchronization but not Full Migration, specify a point in time from which to start migrating data. The default value is the current system time. For more information, see Configure an incremental synchronization offset.

    • Reverse Incremental

      The parameters in this section appear only if you select Reverse Incremental Synchronization on the Select Migration Types page. By default, the Reuse Incremental Synchronization Configuration option is selected.

      image

      You can also clear this option and configure the parameters as needed.

      Parameter

      Description

      Write Concurrency

      This parameter specifies the number of concurrent threads for writing data to the source during reverse incremental synchronization. The maximum value is 512. A high degree of concurrency may put excessive pressure on the source database and affect your business.

      Reverse Incremental Synchronization Rate Limit

      You can enable the reverse incremental synchronization rate limit as needed. If you enable it, set the RPS (maximum number of data rows that can be synchronized to the source per second during reverse incremental synchronization) and BPS (maximum volume of data that can be synchronized to the source per second during reverse incremental synchronization).

      Note

      The RPS and BPS settings only serve as throttling limits. The actual performance of reverse incremental synchronization is affected by factors such as the source, destination, and instance specifications.

      Incremental Synchronization Start Offset

      • This parameter is not displayed if you select Full Migration as a migration type.

      • If you do not select Full Migration but select Incremental Synchronization, the start offset is based on the forward switchover (if any) by default and cannot be modified.

    • Advanced Options

      The parameters in this section appear only if the destination OceanBase database MySQL tenant is version 4.3.0 or later and you select Schema Migration on the Select Migration Types page.

      image

      The storage classes for destination table objects include Default, Row Store, Column Store, and Hybrid Row-Column Store. This setting specifies the storage class for destination table objects during schema migration. For more information, see default_table_store_format.

      Note

      The Default option automatically adapts to the parameter settings of the destination. During schema migration, table objects are written to the corresponding schema based on the specified storage class.

  7. Click Precheck to precheck the data migration task.

    In the Precheck step, Data Transmission Service checks whether items meet the requirements, such as the read and write permissions of the database user and the network connectivity of the database. You can start the data migration task only after all check items pass. If the precheck fails:

    • You can identify and troubleshoot the problem, and then run the precheck again until it succeeds.

    • You can also click Skip in the Actions column for a failed precheck item. A dialog box appears that describes the impact of skipping this operation. To proceed, click OK.

  8. After the precheck passes, click Start Task.

    If you do not want to start the task immediately, click Save. You can then start the task manually from the Data Migration Task List page or using batch operations. For more information about batch operations, see Batch Operations on Data Migration Tasks.

    Data Transmission Service lets you modify migration objects and their row filtering conditions while a data migration task is running. For more information, see View and modify migration objects and their filter conditions. After the data migration task starts, it performs the migration steps sequentially based on the selected migration types. For more information, see View migration details.

References