OceanBase Migration Service (OMS) is a service that supports data interaction between OceanBase Database and homogeneous or heterogeneous data sources. It supports online data migration and real-time synchronization of incremental data. OMS provides a visualized and centralized management platform. You can migrate data in real time with simple configurations.
This topic describes how to migrate all data from a TiDB database to a MySQL tenant of OceanBase Database by using OMS V4.0.2.
Prerequisites
- You have deployed OMS V4.0.2. For more information about how to deploy OMS, see Deployment types.
- You have a TiDB database to serve as the source data source for data migration.
- You have a MySQL tenant of OceanBase Database to serve as the destination data source for data migration. For more information about user tenants, see User tenants.
Notice
For more information, such as the background, prerequisites, limitations, considerations, and data type mapping, see Migrate data from a TiDB database to a MySQL tenant of OceanBase Database.
Procedure
- Configure the source and destination data sources.
- Create data sources.
- Create a full data migration project and start the project.
- View the data migration status.
Step 1: Configure the source and destination data sources
The following table describes information about the test environment.
| Database | Version | Migration user | Test database name | Test table name |
|---|---|---|---|---|
| Source TiDB database | 5.4.0 | user001 | test_tidb_to_ob | tbl1 |
| Destination MySQL tenant of OceanBase Database | V3.2.4 | user001_backup | test_tidb_to_ob_backup | tbl1_backup |
Step 1.1: Configure the source MySQL database
Create a test database and insert the test data.
Create a test database named
test_tidb_to_ob.MySQL [(none)]> CREATE DATABASE test_tidb_to_ob;Create a table named
tbl1and insert data into it.Switch to the
test_tidb_to_obdatabase.MySQL [(none)]> USE test_tidb_to_ob;Create a table named
tbl1:MySQL [test_tidb_to_ob]> CREATE TABLE tbl1(col1 INT PRIMARY KEY, col2 VARCHAR(20),col3 DATETIME DEFAULT CURRENT_TIMESTAMP);Insert the test data:
MySQL [test_tidb_to_ob]> INSERT INTO tbl1(col1,col2) VALUES(1,'China'),(2,'Taiwan'),(3,'Hong Kong'),(4,'Macao'),(5,'North Korea');View the test data:
MySQL [test_tidb_to_ob]> SELECT * FROM tbl1;Return result:
+------+-------------+---------------------+ | col1 | col2 | col3 | +------+-------------+---------------------+ | 1 | China | 2023-04-28 09:40:27 | | 2 | Taiwan | 2023-04-28 09:40:27 | | 3 | Hong Kong | 2023-04-28 09:40:27 | | 4 | Macao | 2023-04-28 09:40:27 | | 5 | North Korea | 2023-04-28 09:40:27 | +------+-------------+---------------------+ 5 rows in set
Create a migration user and grant the required privileges to the user.
The migration user must have full read privileges.
Example:
Create a migration user named
user001.MySQL [test_tidb_to_ob]> CREATE USER 'user001'@'%' IDENTIFIED BY '******';Grant the
SELECTprivilege to the migration user.MySQL [test_tidb_to_ob]> GRANT SELECT ON *.* TO 'user001';
Step 1.2: Configure the destination MySQL tenant of OceanBase Database
Create a database for the destination MySQL tenant of OceanBase Database.
Example:
Create a database named
test_tidb_to_ob_backup.obclient [(none)]> CREATE DATABASE test_tidb_to_ob_backup;Switch to the
test_tidb_to_ob_backupdatabase.obclient [(none)]> USE test_tidb_to_ob_backup;Create a table named
tbl1_backup:obclient [test_tidb_to_ob_backup]> CREATE TABLE tbl1_backup(col1 INT PRIMARY KEY, col2 VARCHAR(20),col3 DATETIME);Create a migration user and grant the required privileges to the user.
The migration user must have the
CREATE,CREATE VIEW,SELECT,INSERT,UPDATE, andDELETEprivileges on the destination database.The migration user must have the
SELECTprivilege on the MySQL tenant of OceanBase Database.Example:
Create a migration user named
user001_backup.obclient [test_tidb_to_ob_backup]> CREATE USER user001_backup IDENTIFIED BY '******';Grant required privileges to the migration user.
obclient [test_tidb_to_ob_backup]> GRANT CREATE,CREATE VIEW,SELECT,INSERT,UPDATE,DELETE ON test_tidb_to_ob_backup.* TO 'user001_backup';obclient [test_tidb_to_ob_backup]> GRANT SELECT ON *.* TO 'user001_backup';
Step 2: Create data sources
Log on to the OMS console.
On the Data Source Management page, click New Data Source.
Create a TiDB data source as the source data source of the migration project.
Configure the following parameters.
Parameter Description Data Source Type Select TiDB. Data Source Identifier We recommend that you set it to a combination of digits and letters. It must not contain any spaces and cannot exceed 32 characters in length. Region Select the region where the data source resides from the drop-down list. The region is the value that you set for the cm_regionparameter when you deploy OMS.Notice
- This parameter is displayed only when multiple regions are available.
- Make sure that the mappings between the data source and the region are consistent. Otherwise, the migration and synchronization performance can be poor.
Host IP Address The IP address of the server where the TiDB database is located. Port The port number corresponding to the IP address of the server where the TiDB database is located. Username The name of the TiDB database user for data migration or synchronization. Password The password of the database user. Database Name (Optional) The name of the TiDB database. Bind Kafka Data Source A Kafka data source enables OMS to obtain incremental logs from the TiDB database. - If you select this option, select a Kafka data source and the corresponding Kafka topic from the drop-down list.
- If you do not select this option, you cannot select incremental migration when you create a project to migrate data from a TiDB database to a MySQL tenant of OceanBase database.
Remarks (Optional) Additional information about the data source. After you configure the parameters, click Test Connection to verify the network connection between OMS and the data source, as well as the validity of the username and password. After the connection test succeeds, click OK.
Create a physical OceanBase data source as the destination data source of the migration project.
Configure the following parameters.
Parameter Description Data Source Type Select OceanBase and Physical Data Source. Data Source Identifier We recommend that you set it to a combination of digits and letters. It must not contain any spaces and cannot exceed 32 characters in length. Region Select the region where the data source resides from the drop-down list. The region is the value that you set for the cm_regionparameter when you deploy OMS.Notice
- This parameter is displayed only when multiple regions are available.
- Make sure that the mappings between the data source and the region are consistent. Otherwise, the migration and synchronization performance can be poor.
Tenant Type Select MySQL. The type of the OceanBase Database tenant. Valid values: Oracle and MySQL. OCP Cluster (Optional) The OceanBase Cloud Platform (OCP) cluster associated with the data source. Select an OCP cluster from the drop-down list. Note
If the OCP cluster is not available in the list, click Add OCP Cluster and configure the parameters on the Add Associated OCP Cluster page.
- Check whether the data source is managed in the selected OCP cluster.
- This parameter ensures that OMS obtains the incremental data of the OceanBase database. If you do not set this parameter, you cannot select Incremental Migration, Incremental Synchronization, or Reverse Incremental Migration.
Connection Mode Valid values: Manual Input and Command-line Connection String. - Manual Input: Enter the public IP address and port number of the OceanBase database.
- Command-line Connection String: Enter a command-line connection string. This option is optional.
Host IP Address The IP address of the host where the database is located. Port The port number of the host where the database is located. Tenant Name The name of the OceanBase Database tenant. Cluster Name The name of the cluster to which the OceanBase Database tenant belongs. Database Username The username of the OceanBase database user for data migration or synchronization. We recommend that you create a dedicated database user for data migration or synchronization. Database Password The password of the database user. Database Name (Optional) The name of the database. Remarks (Optional) Additional information about the data source. After you configure the parameters, click Test Connection to verify the network connection between OMS and the data source, as well as the validity of the username and password. After the connection test succeeds, click OK.
Step 3: Create a full data migration project and start the project
On the Data Migration page, click Create Migration Project in the upper-right corner.
On the Select Source and Destination page, configure the following parameters.
Parameter Description Migration Project 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. Tag (Optional) Click the field and select a target tag from the drop-down list. You can also click Manage Tags to create, modify, and delete tags. Source Select the created TiDB data source from the drop-down list. Notice
If the TiDB data source for the source database is not bound to a valid Kafka data source or topic, incremental synchronization is not supported.Destination Select the data source created for a MySQL tenant of OceanBase Database from the drop-down list. After you configure the parameters, click Next.
Note
After you read the message in the dialog box, click OK.
On the Select Migration Type page, configure the following parameters.
Options for Migration Type are Schema Migration, Full Migration, Incremental Synchronization, Full Verification, and Reverse Incremental Migration.
Migration type Description Schema Migration The definitions of data objects, such as tables, indexes, constraints, comments, and views, are migrated from the source database to the destination database. Temporary tables are automatically filtered out. Full Migration If you select Full Migration, we recommend that you use the ANALYZEstatement to collect the statistics of the TiDB database before data migration.Incremental Synchronization Incremental Synchronization supports the following DML operations: INSERT,DELETE, andUPDATE. You can select the operations based on your business needs.Note
If you create a TiDB data source without binding it to a Kafka data source, you cannot selectIncremental Synchronization.Full Verification - 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 selected Incremental Synchronization but did not select all DML statements in DML Synchronization, OMS does not support full data verification in this case.
Reverse Incremental Migration You cannot select Reverse Incremental Migration in the following cases: - Multi-table aggregation and synchronization is enabled.
- Multiple source databases map to the same destination database.
Select Full Migration, specify the parameters, and then click Next.
On the Select Migration Objects page, select the migration objects and migration scope.
You can select Specify Objects or Match Rules to specify the migration objects. If you select DDL Synchronization, only the Match Rules option is available.
If you select Specify Objects, select the objects to be migrated on the left and click > to add them to the list on the right. You can select tables and views of one or more databases as the migration objects.
Notice
- The names of tables to be migrated, as well as the names of columns in the tables, must not contain Chinese characters.
- If the database or table name contains a double dollar sign ($$), you cannot create the migration project.
When you migrate data from a TiDB database to a MySQL tenant of OceanBase Database, OMS allows you to import objects through text, rename object names, and remove a single or all migration objects.
Operation Steps Import Objects - In the list on the right of the Specify Migration Scope section, click Import Objects in the upper-right corner.
- In the dialog box that appears, click OK.
Notice
This operation overwrites previous selections. Proceed with caution. - In the Import Objects dialog box, import the objects to be migrated. You can import CSV files to rename databases/tables and set row filtering conditions.
- Click Validate.
- After the validation succeeds, click OK.
Rename OMS allows you to rename migration objects. Settings OMS allows you to use the WHERE clause to filter data by row. You can also view column information about the migration objects in the View Columns section. Remove/Remove All During data mapping, OMS allows you to remove one or more selected objects to be migrated to the destination. - Remove a single migration object: In the list on the right of the Specify Migration Scope section, move the pointer over the object that you want to remove, and then click Remove.
- Remove all migration objects: In the list on the right of the Specify Migration Scope section, click Remove All in the upper-right corner. In the dialog box that appears, click OK.
After you configure the parameters, click Next.
On the Migration Options page, configure the parameters for full migration.
Parameter Description Concurrency for Full Migration The value can be Smooth, Normal, or Fast. Different quantities of resources of the source and destination databases are consumed at different concurrencies. You can define the concurrency for full migration by modifying the configurations of the Full-Verification component. Whether to Allow Destination Table to Be Not Empty During Full Migration If destination tables are allowed to be not empty during full migration, full verification is performed in INmode.Note
You can set this option only when Full Migration is selected on the Select Migration Type page.After you configure the parameters, click Precheck.
On the Precheck page, handle Failed check items.
During the precheck, OMS checks the read and write privileges of the database users and the network connections of the databases. The data migration project can be started only after it passes all check items. If an error is returned during the precheck:
- You can identify and troubleshoot the problem and then perform the precheck again.
- You can also click Skip in the Actions column of a failed precheck item. In the dialog box that appears, you can view the prompt for the consequences of the operation and click OK.
After the precheck succeeds, click Start Project.
Note
If you do not need to start the project now, click Save to go to the details page of the data migration project. You can start the project later as needed.
On the Migration Details page, click Start Forward Switchover.
Wait for the task to complete.
Step 4: View the data migration status
Log on to OceanBase Database to check whether the data has been migrated.
Connect to the MySQL tenant of OceanBase Database.
$obclient -hxxx.xxx.xxx.xxx -P2883 -uxxxx@mysql001#test3242 -p****** -A -Dtest_tidb_to_ob_backupQuery the data in the
tbl1_backuptable.obclient [test_tidb_to_ob_backup]> SELECT * FROM tbl1_backup;Return result:
+------+-------------+---------------------+ | col1 | col2 | col3 | +------+-------------+---------------------+ | 1 | China | 2023-04-28 09:40:27 | | 2 | Taiwan | 2023-04-28 09:40:27 | | 3 | Hong Kong | 2023-04-28 09:40:27 | | 4 | Macao | 2023-04-28 09:40:27 | | 5 | North Korea | 2023-04-28 09:40:27 | +------+-------------+---------------------+ 5 rows in set