Create an AnalyticDB for MySQL synchronization
Preparations
1. Prepare an AnalyticDB for MySQL instance and define a table schema. Create an AnalyticDB for MySQL cluster in the AnalyticDB for MySQL console. When you synchronize data from DataHub to an AnalyticDB for MySQL cluster, DataHub fields are mapped to the corresponding AnalyticDB for MySQL data types. The following table lists the mappings.
|
DataHub |
MySQL |
|
TINYINT |
TINYINT |
|
SMALLINT |
SMALLINT |
|
INTEGER |
INT |
|
BIGINT |
BIGINT |
|
STRING |
VARCHAR |
|
BOOLEAN |
BOOLEAN / TINYINT |
|
FLOAT |
FLOAT |
|
DOUBLE |
DOUBLE |
|
TIMESTAMP |
TIMESTAMP / BIGINT |
|
DECIMAL |
DECIMAL |
The TINYINT, SMALLINT, INTEGER, and FLOAT types in DataHub are supported in DataHub SDK for Java V2.16.1-public and later. 2.Synchronization description: (1) DataHub synchronizes only TUPLE-type data to AnalyticDB for MySQL. (2) ReplaceInto and IgnoreInto modes: In ReplaceInto mode, the REPLACE INTO statement overwrites existing data when a primary key conflict occurs. In IgnoreInto mode, the INSERT IGNORE INTO statement ignores conflicts and writes only non-duplicate data. (3) Data synchronization latency is typically in seconds. After data is written to DataHub, it is synchronized to AnalyticDB for MySQL within seconds. Network exceptions may cause duplicate data updates, but at-least-once delivery is guaranteed. (4) The write performance of AnalyticDB for MySQL affects synchronization performance. Poor instance performance may slow down synchronization and cause data to accumulate. In extreme cases, data may be lost if the synchronization latency exceeds the data lifecycle.
Create a DataConnector
Go to the Project List page, the project details page, and the topic details page in sequence.
Click the + Synchronization button in the upper-right corner to create a synchronization task.
In the Create Connector dialog box, configure the following parameters:
Parameter | Description |
Host | The host address of AnalyticDB for MySQL. An internal address must be specified to ensure network connectivity. |
Port | The default value is |
Database | The database name in AnalyticDB for MySQL. |
Table | The table name in AnalyticDB for MySQL. |
User | The username used to access AnalyticDB for MySQL. |
Password | The password used to access AnalyticDB for MySQL. |
Write Mode | Select |
Import Fields | Select the fields to synchronize. |
Start Time | Select the start time for data synchronization. |
After configuration is complete, click Create.
The following list describes some configurations for creating synchronization tasks in the console. For more flexible operations, see the SDK documentation.
-
Host: the endpoint of AnalyticDB for MySQL. To ensure that the service can be connected, you must enter the
internal endpoint. -
Import Fields: the fields to be synchronized to AnalyticDB for MySQL. You can synchronize all the fields of the DataHub topic or part of them based on your business requirements.
-
Write Mode: the write mode. Valid values:
-
IGNORE: This mode ignores duplicate data. The
INSERT IGNORE INTOstatement is executed to write data. -
OVERWRITE: This mode updates duplicate data. The
REPLACE INTOstatement is executed to write data.
-
Example
-
Create an AnalyticDB for MySQL instance and a table with the defined table schema in the AnalyticDB for MySQL console.
-
Create a topic in the DataHub console. In this example, the created topic is of the TUPLE type.
The topic schema contains three fields:
-
field1: STRING type, NOT NULL -
field2: BIGINT type, NOT NULL -
field3: DOUBLE type, NOT NULL
3. Create a DataConnector. Select IGNORE from the Write Mode drop-down list and all fields from the Import Fields drop-down list.
4. Write data of the TUPLE type to the created topic. The following table shows the four records that are written to the topic.
|
Sequence |
field1 |
field2 |
field3 |
|
47502 |
f_1 |
1 |
1 |
|
47503 |
f_2 |
2 |
2 |
|
47504 |
f_1 |
1 |
1 |
|
47505 |
f_2 |
2 |
2 |
5. Verify the synchronized data. Connect to AnalyticDB for MySQL from a client and view the data. The query results are shown below.
mysql> select * from wurao_tuple_test_001;
+--------+--------+--------+
| field1 | field2 | field3 |
+--------+--------+--------+
| f_1 | 1 | 1.00 |
| f_2 | 2 | 2.00 |
| f_1 | 1 | 1.00 |
| f_2 | 2 | 2.00 |
+--------+--------+--------+
4 rows in set (0.00 sec)
mysql>
Synchronize data to AnalyticDB for MySQL V3.0
For more information about synchronization to AnalyticDB for MySQL V3.0, see Synchronize data with RDS, MySQL, and AnalyticDB.