This topic describes how to synchronize data from a MySQL database to a DataHub instance.
Prerequisites
You have enabled binlogs for the self-managed MySQL database. For more information, see Enable binlogs for the MySQL database.
A database user is created to implement the data migration tasks for the source MySQL database and granted the required privileges. For more information, see Create a database user.
Limits
The name of a table to be synchronized, as well as the names of columns in the table, must not contain Chinese characters.
OMS supports data synchronization when character sets are configured with UTF8 and GBK coding.
When data transfer is resumed on a link, some data (within the last minute) may be duplicated, and deduplication is required in downstream applications.
If incremental parsing is required for the MySQL database, you must specify the ID of the MySQL server.
DataHub has the following limits:
DataHub limits the size of a message based on the cloud environment, usually to 1 MB.
DataHub sends messages in batches, with each batch sized no more than 4 MB. If a single message meets the conditions for sending, you can modify the
batch.sizeparameter at the connector sink. By default, 20 messages are sent at a time within one second.
When you synchronize incremental data from a MySQL database to a DataHub instance, the initial schema is synchronized to the DataHub schema. The following table lists data types supported by MySQL.
| Data types | DataHub data type |
|---|---|
| BIT | BIGINT |
| CHAR | STRING |
| BINARY | STRING |
| VARBINARY | STRING |
| INT | BIGINT |
| TINYINT | BIGINT |
| SMALLINT | BIGINT |
| MEDIUMINT | BIGINT |
| BIGINT | BIGINT |
| FLOAT | FLOAT |
| DOUBLE | DOUBLE |
| DECIMAL | DECIMAL |
| DATE | STRING |
| TIME | STRING |
| YEAR | STRING |
| DATETIME | STRING |
| TIMESTAMP | STRING |
| VARCHAR | STRING |
| TINYBLOB | STRING |
| TINYTEXT | STRING |
| BLOB | STRING |
| TEXT | STRING |
| MEDIUMBLOB | STRING |
| MEDIUMTEXT | STRING |
| LONGBLOB | STRING |
| LONGTEXT | STRING |
Supplemental properties
If you manually create a topic, add the following properties to the DataHub schema before you start a synchronization project. If OMS automatically creates a topic and synchronizes the schema, OMS automatically adds the following properties.
Notice
The following table applies only to tuple topics.
| Property | Type | Description |
|---|---|---|
| oms_timestamp | STRING | The time when the change was made. |
| oms_table_name | STRING | The new table name of the source table. |
| oms_database_name | STRING | The new database name of the source database. |
| oms_sequence | STRING | The modified sequence number. The primary key on one server progressively increases. |
| oms_record_type | STRING | The change type. Valid values: UPDATE, INSERT, and DELETE. |
| oms_is_before | STRING | Specifies whether the data is the original data when the change type is UPDATE. Y indicates that the data is the original data. |
| oms_is_after | STRING | Specifies whether the data is the modified data when the change type is UPDATE. Y indicates that the data is the modified data. |
Procedure
Create a data synchronization project.
Log on to the OMS console.
In the left-side navigation pane, click Data Synchronization.
On the Data Synchronization page, click Create Synchronization Project in the upper-right corner.
On the Select Source and Destination page, configure the parameters.
Parameter Description Synchronization Project Name We recommend that you set it to a combination of Chinese characters, digits, and letters. It must not contain any spaces and cannot exceed 64 characters in length. Label Click the field and select the target tag from the drop-down list. You can click Manage Tags to create, modify, and delete tags. For more information, see Manage data synchronization projects by using tags. Source If you have created a MySQL data source, select it from the drop-down list. If you have not created a data source, click Create Data Source in the drop-down list and create a data source in the dialog box that appears on the right. For more information about the parameters, see Create a MySQL data source. Destination If you have created a DataHub data source, select it from the drop-down list. If you have not created a data source, click Create Data Source in the drop-down list and create a data source in the dialog box that appears on the right. For more information, see Create a DataHub data source. Click Next. On the Select Synchronization Type page, specify Synchronization Type and Configuration for the current data synchronization project.
Synchronization Type and Configuration includes Schema Synchronization and Incremental Synchronization. Schema Synchronization creates a topic. Incremental Synchronization supports only DML Synchronization. The DML operations for synchronization are
Insert,Delete, andUpdate.Click Next. On the Select Synchronization Objects page, select the type and range of topics to be synchronized.
Available topic types are Tuple and Blob. Tuple topics contain records that are similar to data records in databases. Each record contains multiple columns. You can only write a block of binary data as a record to a Blob topic. The data are Base64 encoded for transmission. For more information, visit the documentation center of DataHub.
Select the type of topics to be synchronized and perform the following steps:
In the left-side pane, select the objects to be synchronized.
Click >.
Select a mapping method.
Notice
When you set the topic type to tuple without selecting Schema Synchronization, you can only synchronize a single table to a single topic.
To synchronize a single table, select the mapping method as needed in the Map Object to Topic dialog box and click OK.
If you do not select Schema Synchronization when you set the synchronization type and configuration, you can select only Existing Topics here. If you have selected Schema Synchronization when you set the synchronization type and configuration, you can select only one mapping method to create or select a topic.
For example, if you have selected Schema Synchronization, when you use both the Create Topic and Select Topic mapping methods or rename the topic, a precheck error will be returned due to option conflicts.
Parameter Description Create Topic Enter the name of the new topic in the text box. The topic name can contain letters, digits, and underscores (_) and must start with a letter. It must not exceed 128 characters in length. Select Topic OMS allows you to query DataHub topics. You can click Select Topic, and then find and select the topics to be synchronized from the Existing Topics drop-down list. You can also enter the name of an existing topic and select it after it appears. Batch Generate Topics The format for generating topics in batches is: Topic_${Database Name}_${Table Name}.If you select Create Topic or Batch Generate Topics, you can query the newly created topics in the DataHub instance after schema synchronization is completed. By default, each DataHub topic has two partitions and the data expiration period is 7 days, which cannot be modified.
To synchronize multiple tables, click OK in the dialog box that appears.
If you have selected a tuple topic and multiple tables without selecting Schema Synchronization, after you select a topic and click OK in the Map Object to Topic dialog box, multiple tables are displayed under the topic in the right pane, but only one table can be synchronized. Click Next. A prompt appears, indicating that only one-to-one mapping is supported between tuple topics and tables.
Click OK.
When you synchronize data from a MySQL database to a DataHub instance, OMS allows you to import objects from text data, set sharding columns for tables in the destination database, and remove a single object or all objects. Objects in the destination database are listed in the structure of Topic > Database > Table.
Operation Steps Import Objects - In the list on the right, click Import Objects in the upper-right corner.
- In the dialog box that appears, click OK. Notice
This operation will overwrite previous selections. Proceed with caution. - In the Import Synchronization Objects dialog box, import the objects to be synchronized.
You can import CSV files to rename databases/tables and set row filtering conditions. For more information, see Download and import the settings of synchronization objects. - Click Validate.
- After the validation succeeds, click OK.
Change Topic When the topic type is set to Blob, you can change topics for objects in the destination database. - In the list on the right, move the pointer over the object that you want to change.
- Click Change Topic.
- In the Map Object to Topic dialog box, change the topics to be synchronized.
- Click OK.
Notice
The selected topics and tables will be merged into the selected topic. Proceed with caution.
Settings - In the list on the right, move the pointer over the object that you want to change.
- Click Settings.
- In the Settings dialog box, click Shard Columns and select the target sharding columns in the drop-down list. You can select multiple fields as sharding columns. This parameter is optional.
Unless otherwise specified, select the primary keys as sharding columns. If the primary keys are not load-balanced, select fields with unique identifiers and whose load is balanced as sharding columns.
Ensure that the selected sharding columns are correct. An incorrect sharding column will cause data synchronization to fail. Sharding columns can be used for the following purposes:- Load balancing: Threads used for sending messages can be recognized based on the sharding columns if the destination table supports concurrent writes.
- Orderliness: OMS ensures that messages are received in order if the values of the sharding columns are the same. The orderliness specifies the sequence of executing DML statements for a column.
- Click OK.
Remove/Remove All OMS allows you to remove one or more objects from the destination database during data mapping. - Remove a single synchronization object
In the list on the right of the selection section, hover the pointer over the target object, and click Remove. The synchronization object is removed. - Remove all synchronization objects
In the list on the right of the selection section, click Remove All in the upper-right corner. In the dialog box that appears, click OK to remove all synchronization objects.
Click Next. On the Synchronization Options page, specify the following parameters.
Parameter Description Synchronization Settings Incremental Synchronization Start Timestamp This parameter specifies to synchronize the data after the synchronization start timestamp. The default value is the current system time. You can select a point in time or enter a timestamp.
Notice
You can select the current time or a point in time earlier than the current time.
This parameter is closely related to the retention period of archived logs. Generally, you can start data synchronization from the current timestamp.Advanced Options Serialization Method The message format for synchronizing data to a DataHub instance. Valid values: Default, Canal, Dataworks (version 2.0 supported), SharePlex, and DefaultExtendColumnType. For more information, see Data formats. Notice
This parameter is available only when the topic type is set to Blob on the Select Synchronization Type page.Advanced Options Enable Intra-Transaction Sequence Specifies whether to maintain order within a transaction. If this feature is enabled, OMS marks the sequence number for a transaction to be sent to a downstream node.
Notice
This parameter is valid only for the SharePlex format and is intended for you to obtain the sequence numbers of the DML statements that form a transaction.
For example, if a transaction contains 10 DML statements numbered from 1 to 10, OMS will deliver these statements to the destination database in the same order.
If this option is enabled, the system performance may be affected. Choose whether to enable it based on the business characteristics.Advanced Options Partitioning Rules The rule for synchronizing data from the source database to a DataHub topic. Valid values: Hash and Table. - Hash indicates that OMS uses a hash algorithm to select the shard of a DataHub topic based on the value of the primary key or sharding column.
- Table indicates that OMS delivers all data in a table to the same partition and uses the table name as the hash key.
Advanced Options Business System Identification (Optional) Identifies the source business system of data. The business system identifier consists of 1 to 20 characters. Click Precheck.
During the precheck, OMS checks whether the schema of the logical table is the same as that of the physical table. OMS checks only the column name, column type, and whether the column is empty, but does not check the length or default value. If an error is returned:
You can troubleshoot the error and run the precheck again.
You can also click Skip in the Actions column of the precheck item that returns the error. Then, a dialog box appears, indicating the impact that may be caused if you choose to skip this check item. If you want to continue, click OK in the dialog box.
Click Start Project. If you do not need to start the project now, click Save to go to the details page of the data synchronization project. You can start the project later as needed.
OMS allows you to modify synchronization objects when a data synchronization project is running. For more information, see View and modify synchronization objects. After a data synchronization project is started, the synchronization objects will be executed based on the selected synchronization type. For more information, see the "View synchronization details" section in the View details of a data synchronization project topic.
If data access fails due to a network failure or the slow startup of processes, go to the project list or the project details page and click Restore.