This topic describes the data types and parameters that are supported by HybridDB for MySQL Writer and how to configure HybridDB for MySQL Writer by using the codeless user interface (UI) and code editor.
HybridDB for MySQL Writer can write data to tables stored in HybridDB for MySQL databases.
HybridDB for MySQL Writer connects to a remote HybridDB for MySQL database by using
Java Database Connectivity (JDBC) and executes the
INSERT INTO
or REPLACE INTO
statement to write data to the HybridDB for MySQL database. HybridDB for MySQL uses
the InnoDB engine so that data is written to the database in batches.
Note Before you configure HybridDB for MySQL Writer, you must add a HybridDB for MySQL
data source. For more information, see Configure a HybridDB for MySQL connection.
HybridDB for MySQL Writer is designed for data developers to write data from data
warehouses to HybridDB for MySQL databases. HybridDB for MySQL Writer can also be
used as a data migration tool by users such as database administrators. HybridDB for
MySQL Writer obtains data from a reader.
Note A synchronization node that uses HybridDB for MySQL Writer must have at least the
permissions to execute the
INSERT INTO
statement. Whether other permissions are required depends on the SQL statements that
you specify in the preSql and postSql parameters when you configure the node.
Data types
HybridDB for MySQL Writer supports most HybridDB for MySQL data types. Make sure that the data types of your database are supported.
The following table lists the data types that are supported by HybridDB for MySQL
Writer.
Category | HybridDB for MySQL data type |
---|---|
Integer | INT, TINYINT, SMALLINT, MEDIUMINT, BIGINT, and YEAR |
Floating point | FLOAT, DOUBLE, and DECIMAL |
String | VARCHAR, CHAR, TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT |
Date and time | DATE, DATETIME, TIMESTAMP, and TIME |
Boolean | BOOLEAN |
Binary | TINYBLOB, MEDIUMBLOB, BLOB, LONGBLOB, and VARBINARY |
Parameters
Parameter | Description | Required | Default value |
---|---|---|---|
datasource | The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor. | Yes | No default value |
table | The name of the table to which you want to write data. | Yes | No default value |
writeMode | The write mode. Valid values:
|
No | insert |
column | The names of the columns to which you want to write data. Separate the names with
commas (,), such as "column":["id","name","age"] . If you want to write data to all the columns in the destination table, set the value
to an asterisk (*), such as "column":["*"] .
|
Yes | No default value |
preSql | The SQL statement that you want to execute before the synchronization node is run. For example, you can set this parameter to the SQL statement that is used to delete outdated data. You can execute only one SQL statement on the codeless UI and multiple SQL statements in the code editor. | No | No default value |
postSql | The SQL statement that you want to execute after the synchronization node is run. For example, you can set this parameter to the SQL statement that is used to add a timestamp. You can execute only one SQL statement on the codeless UI and multiple SQL statements in the code editor. | No | No default value |
batchSize | The number of data records to write at a time. Set this parameter to an appropriate value based on your business requirements. This greatly reduces the interactions between Data Integration and HybridDB for MySQL and increases throughput. If you set this parameter to an excessively large value, an out of memory (OOM) error may occur during data synchronization. | No | 1,024 |
Configure HybridDB for MySQL Writer by using the codeless UI
- Configure data sources.
Configure Source and Target for the synchronization node.
Parameter Description Connection The name of the data source to which you want to write data. This parameter is equivalent to the datasource parameter that is described in the preceding section. Table This parameter is equivalent to the table parameter that is described in the preceding section. Statement Run Before Writing The SQL statement that you want to execute before the synchronization node is run. This parameter is equivalent to the preSql parameter that is described in the preceding section. Statement Run After Writing The SQL statement that you want to execute after the synchronization node is run. This parameter is equivalent to the postSql parameter that is described in the preceding section. Solution to Primary Key Violation The write mode. This parameter is equivalent to the writeMode parameter that is described in the preceding section. You can select the desired write mode. - Configure field mappings. This operation is equivalent to setting the column parameter that is described in the preceding section. Fields in the source on the
left have a one-to-one mapping with fields in the destination on the right.
Operation Description Map Fields with the Same Name Click Map Fields with the Same Name to establish mappings between fields with the same name. The data types of the fields must match. Map Fields in the Same Line Click Map Fields in the Same Line to establish mappings between fields in the same row. The data types of the fields must match. Delete All Mappings Click Delete All Mappings to remove the mappings that are established. Auto Layout Click Auto Layout. Then, the system automatically sorts the fields based on specific rules.
Configure HybridDB for MySQL Writer by using the code editor
For more information about how to configure a synchronization node by using the code editor, see Create a sync node by using the code editor.
In the following code, a synchronization node is configured to write data to HybridDB
for MySQL. For more information about the parameters, see the preceding parameter
description.
{
"type": "job",
"steps": [
{
"parameter": {},
{
"parameter": {
"postSql": [],// The SQL statement that you want to execute after the synchronization node is run.
"datasource": "px_aliyun_hy***",// The name of the data source.
"column": [// The names of the columns to which you want to write data.
"id",
"name",
"sex",
"salary",
"age",
"pt"
],
"writeMode": "insert",// The write mode.
"batchSize": 256,// The number of data records to write at a time.
"encoding": "UTF-8",// The encoding format.
"table": "person_copy",// The name of the table to which you want to write data.
"preSql": []// The SQL statement that you want to execute before the synchronization node is run.
},
"name": "Writer",
"category": "writer"
}
],
"version": "2.0",// The version number.
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
},
"setting": {
"errorLimit": {// The maximum number of dirty data records allowed.
"record": ""
},
"speed": {
"concurrent": 7,// The maximum number of parallel threads.
"throttle": true,// Specifies whether to enable bandwidth throttling. The value false indicates that bandwidth throttling is disabled, and the value true indicates that bandwidth throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"mbps": 1,// The maximum transmission rate.
}
}
}