DataWorks provides MariaDB Reader and MariaDB Writer for you to read data from and write data to MariaDB data sources. This topic describes the capabilities of synchronizing data from or to MariaDB data sources.
Supported MariaDB versions
Batch data read and write
MariaDB 5.5.x, MariaDB 10.0.x, MariaDB 10.1.x, MariaDB 10.2.x, and MariaDB 10.3.x are supported. Data of views can be read during batch synchronization.
Supported data types
For information about all data types in each MariaDB version, see the official MariaDB documentation. The following table provides the support status of main data types in MariaDB 10.3.x.
Data type | MariaDB Reader for batch data read | MariaDB Writer for batch data write |
TINYINT | Supported | Supported |
SMALLINT | Supported | Supported |
INTEGER | Supported | Supported |
BIGINT | Supported | Supported |
FLOAT | Supported | Supported |
DOUBLE | Supported | Supported |
DECIMAL/NUMBERIC | Supported | Supported |
REAL | Not supported | Not supported |
VARCHAR | Supported | Supported |
JSON | Supported | Supported |
TEXT | Supported | Supported |
MEDIUMTEXT | Supported | Supported |
LONGTEXT | Supported | Supported |
VARBINARY | Supported | Supported |
BINARY | Supported | Supported |
TINYBLOB | Supported | Supported |
MEDIUMBLOB | Supported | Supported |
LONGBLOB | Supported | Supported |
ENUM | Supported | Supported |
SET | Supported | Supported |
BOOLEAN | Supported | Supported |
BIT | Supported | Supported |
DATE | Supported | Supported |
DATETIME | Supported | Supported |
TIMESTAMP | Supported | Supported |
TIME | Supported | Supported |
YEAR | Supported | Supported |
LINESTRING | Not supported | Not supported |
POLYGON | Not supported | Not supported |
MULTIPOINT | Not supported | Not supported |
MULTILINESTRING | Not supported | Not supported |
MULTIPOLYGON | Not supported | Not supported |
GEOMETRYCOLLECTION | Not supported | Not supported |
Prepare a MariaDB environment before data synchronization
Before you use DataWorks to synchronize data from or to a MariaDB data source, you must prepare a MariaDB environment. This ensures that a synchronization task can be configured and can synchronize data from or to the MariaDB data source as expected. The following information describes how to prepare a MariaDB environment for data synchronization from or to a MariaDB data source.
Preparation 1: Check the version of your MariaDB database
Data Integration has specific requirements for the MariaDB version. You can refer to Supported MariaDB versions to check whether the version of your MariaDB database meets the requirements. You can execute the related statement to check the version of your MariaDB database.
Preparation 2: Prepare an account that has the required permissions
We recommend that you plan and create an account for DataWorks to access your MariaDB database. To prepare such an account, perform the following steps:
Create an account. This step is optional.
For more information, see Create an account used to access a MariaDB database.
Grant the required permissions to the account.
Batch data read: The account must have the SELECT permission.
Batch data write: The account must have the INSERT, DELETE, and UPDATE permissions.
Execute the following statement to grant permissions to the account. Alternatively, grant the SUPER permission to the account. Replace Account for data synchronization with the created account when you execute the statement.
-- CREATE USER 'Account for data synchronization'@'%' IDENTIFIED BY 'Password'; //Create an account that can be used for data synchronization and specify a password. This way, you can use the account and password to access the database from any host. % indicates a host. GRANT SELECT, INSERT, DELETE,UPDATE CLIENT ON *.* TO 'Account for data synchronization'@'%'; //Grant the SELECT, INSERT, DELETE, and UPDATE permissions to the account.
Develop a data synchronization task
For information about the entry point for and the procedure of configuring a data synchronization task, see the following sections. For information about the parameter settings, view the infotip of each parameter on the configuration tab of the task.
Add a data source
Before you configure a data synchronization task to synchronize data from or to a specific data source, you must add the data source to DataWorks. For more information, see Add and manage data sources.
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 code editor and Configure a batch synchronization task by using the codeless UI.
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.
Appendix: Code and parameters
Appendix: Configure a batch synchronization task by using the code editor
If you use the code editor to configure a batch synchronization task, you must configure parameters for the reader and writer of the related data source based on the format requirements in the code editor. For more information about the format requirements, see Configure a batch synchronization task by using the code editor. The following information describes the configuration details of parameters for the reader and writer in the code editor.
Code for MariaDB Reader
{
"type":"job",
"version":"2.0",// The version number.
"steps":[
{
"stepType":"mariadb",// The plug-in name.
"parameter":{
"column":[// The names of the columns.
"id"
],
"connection":[
{ "querySql":["select a,b from join1 c join join2 d on c.id = d.id;"], // The SQL statement that is used to read data from the source table.
"datasource":"",// The name of the data source.
"table":[// The name of the source table. The table name must be enclosed in brackets [].
"xxx"
]
}
],
"where":"",// The WHERE clause.
"splitPk":"",// The shard key.
"encoding":"UTF-8"// The encoding format.
},
"name":"Reader",
"category":"reader"
},
{
"stepType":"stream",
"parameter":{},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":"0"// The maximum number of dirty data records allowed.
},
"speed":{
"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.
"concurrent":1,// The maximum number of parallel threads.
"mbps":"12"// The maximum transmission rate. Unit: MB/s.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Parameters in code for MariaDB 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. The following examples show the advanced usage of the table parameter. In the examples, the table parameter is used to specify a table range.
Note MariaDB Reader reads data from the columns that are specified by the column parameter in the partitions that are specified by the table parameter. If a specified partition or column does not exist, the synchronization task fails. | 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 columns in the source table.
| Yes | No default value |
splitPk | The field that is used for data sharding when MariaDB 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 way, data can be synchronized more efficiently.
| No | No default value |
where | The WHERE clause. For example, you can set this parameter to gmt_create > $bizdate to read the data that is generated on the current day.
| 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 configure this parameter, MariaDB Reader ignores the settings of the table, column, and splitPk parameters and 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 select a,b from table_a join table_b on table_a.id = table_b.id. The priority of the querySql parameter is higher than the priorities of the table, column, where, and splitPk parameters. If you configure the querySql parameter, MariaDB Reader ignores the settings of the table, column, where, and splitPk parameters. The system parses the information, such as the username and password, of the data source specified by the datasource parameter from the querySql parameter. Note The name of the querySql parameter is case-sensitive. For example, querysql does not take effect. | No | No default value |
Code for MariaDB Writer
{
"type":"job",
"version":"2.0",// The version number.
"steps":[
{
"stepType":"stream",
"parameter":{},
"name":"Reader",
"category":"reader"
},
{
"stepType":"mariadb",// The plug-in name.
"parameter":{
"postSql":[],// The SQL statement that you want to execute after the synchronization task is run.
"datasource":"",// The name of the data source.
"column":[// The names of the columns.
"id",
"value"
],
"writeMode":"insert into",// The write mode. Valid values: insert into, replace into, and on duplicate key update.
"batchSize":1024,// The number of data records to write at a time.
"table":"",// The name of the table.
"preSql":[
"delete from XXX;" // The SQL statement that you want to execute before the synchronization task is run.
]
},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{// The maximum number of dirty data records allowed.
"record":"0"
},
"speed":{
"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.
"concurrent":1, // The maximum number of parallel threads.
"mbps":"12"// The maximum transmission rate. Unit: MB/s. Setting this parameter to an appropriate value can reduce read workloads on the source and write workloads on the destination.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Parameters in code for MariaDB 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: insert into, on duplicate key update, and replace into.
| No | insert into |
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 this parameter to an asterisk (*), such as "column":["*"]. | Yes | No default value |
preSql | The SQL statement that you want to execute before the synchronization task is run. You can execute only one SQL statement on the codeless UI and multiple SQL statements in the code editor. For example, you can execute the TRUNCATE TABLE tablename statement to delete outdated data before the synchronization task is run. Note If you specify multiple SQL statements, the statements are not executed in the same transaction. | No | No default value |
postSql | The SQL statement that you want to execute after the synchronization task is run. You can execute only one SQL statement on the codeless UI and multiple SQL statements in the code editor. For example, you can execute the ALTER TABLE tablename add colname timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP statement to add a timestamp after the synchronization task is run. Note If you specify multiple SQL statements, the statements are not executed in the same transaction. | 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 MariaDB 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 | 256 |
updateColumn | The names of columns that are updated when a primary key conflict or unique index conflict occurs. This parameter takes effect only when the writeMode parameter is set to on duplicate key update. Separate multiple column names with commas (,). Example: "updateColumn":["name", "age"]. | No | No default value |