DataWorks provides HybridDB for MySQL Reader and HybridDB for MySQL Writer for you to read data from and write data to HybridDB for MySQL data sources. This topic describes the capabilities of synchronizing data from or to HybridDB for MySQL data sources.
Limits
Data of views can be read during batch synchronization.
HybridDB for MySQL Reader can read tables and views. If you use HybridDB for MySQL Reader to read data from tables, you can specify all or some of the columns in the tables in sequence, change the column order, specify constant fields, and configure HybridDB for MySQL functions, such as now().
Data type mappings
The following table lists the data type mappings based on which HybridDB for MySQL Reader or HybridDB for MySQL Writer converts data types.
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 | BOOL |
Binary | TINYBLOB, MEDIUMBLOB, BLOB, LONGBLOB, and VARBINARY |
Data types that are not listed in the preceding table are not supported.
HybridDB for MySQL Reader processes TINYINT(1) as an integer data type.
Add a data source
Before you develop a synchronization task in DataWorks, you must add the required data source to DataWorks by following the instructions in Add and manage data sources. You can view the infotips of parameters in the DataWorks console to understand the meanings of the parameters when you add a data source.
Develop a data synchronization task
For information about the entry point for and the procedure of configuring a synchronization task, see the following configuration guides.
Configure a batch synchronization task to synchronize data of a single table
For more information about the configuration procedure, see Configure a batch synchronization task by using the codeless UI and Configure a batch synchronization task by using the code editor.
For information about all parameters that are configured and the code that is run when you use the code editor to configure a batch synchronization task, see Appendix: Code and parameters.
Configure synchronization settings to implement batch synchronization of all data in a database
For more information about the configuration procedure, see Configure a synchronization task in Data Integration.
Appendix: Code and parameters
Configure a batch synchronization task by using the code editor
If you want to configure a batch synchronization task by using the code editor, you must configure the related parameters in the script based on the unified script format requirements. For more information, see Configure a batch synchronization task by using the code editor. The following information describes the parameters that you must configure for data sources when you configure a batch synchronization task by using the code editor.
Code for HybridDB for MySQL Reader
Sample code for HybridDB for MySQL Reader to read data from a table that is not sharded:
{
"type": "job",
"steps": [
{
"parameter": {
"datasource": "px_aliyun_hymysql",// 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"
],
"where": "id=10001",// The WHERE clause.
"splitPk": "id",// The shard key.
"table": "person"// The name of the source table.
},
"name": "Reader",
"category": "reader"
},
{
"parameter": {}
],
"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 throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"mbps": 1 // The maximum transmission rate. Unit: MB/s.
}
}
}Parameters in code for HybridDB for MySQL Reader
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 from which you want to read data. Each synchronization task can be used to synchronize data to only one table. | Yes | No default value |
column | The names of the columns from which you want to read data. Specify the names in a JSON array. The default value is [*], which indicates all the columns in the source table.
| Yes | No default value |
splitPk | The field that is used for data sharding when HybridDB for MySQL Reader reads data. If you configure this parameter, the source table is sharded based on the value of this parameter. Data Integration then runs parallel threads to read data. This improves data synchronization efficiency.
| No | No default value |
where | The WHERE clause. For example, you can set this parameter to
| No | No default value |
querySql (advanced parameter, which is available only in the code editor) | The SQL statement that is used for refined data filtering. If you specify this parameter, HybridDB for MySQL Reader filters data based only on the value of this parameter. For example, if you want to join multiple tables for data synchronization, set this parameter to | No | No default value |
singleOrMulti (available only for a sharded table) | Specifies that the source table is a sharded table. After you switch from the codeless UI to the code editor, the | Yes | multi |
Code for HybridDB for MySQL Writer
{
"type": "job",
"steps": [
{
"parameter": {},
{
"parameter": {
"postSql": [],// The SQL statement that you want to execute after the synchronization task is run.
"datasource": "px_aliyun_hy***",// The name of the data source.
"column": [// The names of the columns.
"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 destination table.
"preSql": []// The SQL statement that you want to execute before the synchronization task 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 throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"mbps": 1,// The maximum transmission rate. Unit: MB/s.
}
}
}Parameters in code for HybridDB for MySQL Writer
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 | Yes | No default value |
preSql | The SQL statement that you want to execute before the batch synchronization task 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 batch synchronization task 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 |