All Products
Search
Document Center

DataWorks:MariaDB data source

Last Updated:Nov 15, 2023

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:

  1. Create an account. This step is optional.

    For more information, see Create an account used to access a MariaDB database.

  2. 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.

  3. 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

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.

  • Set the table parameter to 'table_[0-99]'. This value indicates that MariaDB Reader reads data from the tables 'table_0' to 'table_99' in sharded databases.

  • Set the table parameter to '"table": ["table_00[0-9]", "table_0[10-99]", "table_[100-999]"]'. This value indicates that MariaDB Reader reads data from tables 'table_000' to 'table_999'. You can use this method only if the numerical suffixes of the names of your tables are of the same length.

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.

  • You can select specific columns to read.

  • The column order can be changed. This indicates that you can specify columns in an order different from the order specified by the schema of the source table.

  • Constants are supported. The column names must be arranged in compliance with the SQL syntax supported by MariaDB, such as ["id","table","1","'mingya.wmy'","'null'","to_char(a+1)","2.3","true"].

    • id: a column name.

    • table: the name of a column that contains reserved keywords.

    • 1: an integer constant.

    • 'mingya.wmy': a string constant, which is enclosed in single quotation marks (').

    • null:

  • " " indicates an empty string.

  • null indicates a null value.

  • 'null' indicates the string null.

    • to_char(a+1): a function expression that is used to calculate the length of a string.

    • 2.3: a floating-point constant.

    • true: a Boolean value.

  • The column parameter must explicitly specify all the columns from which you want to read data. This parameter cannot be left empty.

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.

  • We recommend that you set the splitPk parameter to the name of the primary key column of the table. Data can be evenly distributed to different shards based on the primary key column, instead of being intensively distributed only to specific shards.

  • The splitPk parameter supports sharding for data only of integer data types. If you set the splitPk parameter to a field of an unsupported data type, such as a string, floating point, or date data type, the setting of this parameter is ignored, and a single thread is used to read data.

  • If the splitPk parameter is not provided or is left empty, a single thread is used to read data.

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.

  • You can use the WHERE clause to synchronize incremental data. If the where parameter is not provided or is left empty, MariaDB Reader reads all data.

  • Do not set the where parameter to limit 10. This value does not conform to the constraints of MariaDB on the SQL WHERE clause.

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.

  • insert into: If a primary key conflict or unique index conflict occurs, data cannot be written to the conflicting rows, and the data that is not written to these rows is regarded as dirty data. If you configure a synchronization task by using the code editor, set writeMode to insert into.

  • on duplicate key update: If no primary key conflict or unique index conflict occurs, the data is processed in the same way as that when you set this parameter to insert into. If a conflict occurs, specified fields in the original rows are replaced with new rows, and data is written to MariaDB. If you configure a synchronization task by using the code editor, set writeMode to on duplicate key update.

  • replace into: If no primary key conflict or unique index conflict occurs, the data is processed in the same way as that when you set this parameter to insert into. If a conflict occurs, the original rows are deleted, and new rows are inserted. This indicates that all data in the original rows are replaced. If you configure a synchronization task by using the code editor, set writeMode to 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