The real-time synchronization pipeline from MySQL to LogHub (SLS) synchronizes incremental data to the destination. This topic describes how to create a task to synchronize an entire database from MySQL to LogHub (SLS) in real time and how to monitor its status.
Prerequisites
-
You have purchased a serverless resource group.
-
You have created a MySQL data source and a LogHub (SLS) data source. For more information, see Data source configuration.
-
A network connection must exist between the resource group and the data sources. For more information, see Overview of network connection solutions.
Procedure
Step 1: Select the synchronization task type
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Integration.
-
In the left-side navigation pane, click Synchronization Task. At the top of the page, click Create Synchronization Task. In the dialog box, configure the following basic settings:
-
Source Type:
MySQL. -
Destination Type:
LogHub. -
Specific Type:
real-time synchronization of entire database. -
Synchronization Mode: incremental synchronization. This method continuously synchronizes binlog data from your business database to LogHub.
-
Step 2: Configure network and resources
-
In the Network and Resource Configuration section, select the Resource Group for the synchronization task. You can allocate compute units (CUs) for the Task Resource Usage.
-
For Source Information, select the added
MySQLdata source. For Destination, select the addedLogHubdata source. Then, click Test Connectivity. -
After both connectivity tests pass, click Next.
Step 3: Select databases and tables
In this step, in the Source Table area, select the source tables to synchronize and click the
icon to move them to the Selected Tables area on the right.
In the Source Table area, you can also select tables by pasting a list. You can select up to 5,000 tables.
-
Select Specific Databases/Tables:
-
In the Source Table area, use the Database Filter and Table Filter fields to search for the databases and tables you want to synchronize. Select the items and click the
icon to move them to the Selected Databases/Tables area. -
In the Selected Databases/Tables area, use the Database Filter and Table Filter fields to find any tables you want to exclude. Select them and click the
icon to move them back to the Source Databases/Tables area.
-
-
Use regex for table selection (supports adding/removing tables by regex during runtime).:
Enter regular expressions in the Database Filter and Table Filter fields. Click Confirm to select the matching tables.
NoteFor example, to synchronize tables from databases with names that start with
aand tables with names that start withorder, entera.*in the Database Filter box andorder.*in the Table Filter box.
Step 4: Map destination tables
After you select the tables to synchronize, they are automatically displayed on this page. However, the destination tables are not yet mapped. You must define the mappings between the source and destination tables, which specify how data is read and written. After you define the mappings, click Refresh Mapping to proceed to the next step. You can refresh the mappings now or after you customize the rules for destination tables.
1. Select the destination Logstore
In the Destination Logstore column, select a destination Logstore for the synchronization task from the drop-down list. You can also select multiple tables and then click to configure them in bulk.
2. Configure DML rules
Data Integration provides default DML processing rules. You can also define custom processing rules for DML commands that write to the destination tables.
-
Define rules for a single table: Click Configuration in the DML Rule Configuration column for a specific table to define DML rules for it.
-
Define rules in bulk: Select all tables to be synchronized, and at the bottom of the list, click .
Step 5: Configure alerts
To prevent data synchronization delays caused by task errors, you can configure alert policies for synchronization tasks.
-
Click Alert Settings in the upper-right corner of the page to go to the Alert Rule Configurations for Real-time Synchronization Subnode settings page.
-
Click Add Alert Rule to configure an alert rule.
NoteThe alert rules defined here apply to the real-time synchronization subtasks generated by this task. After you finish configuring the task, you can go to the Run and manage real-time synchronization tasks page to view and modify the monitoring alert rules for the real-time synchronization subtask.
-
Manage alert rules.
For existing alert rules, you can use the alert toggle to enable or disable an alert rule. You can also send alerts to different contacts based on the alert severity level.
Step 6: Configure advanced parameters
To fine-tune the task, click Configuration in the Custom Advanced Parameters column to modify advanced parameters.
-
In the upper-right corner of the page, click Advanced Parameters to go to the advanced parameter configuration page.
-
The following table describes key parameters.
Parameter
Description
Expand business data
Specifies whether to flatten the business data fields from the source table to the top level of the log entry.
-
true: Expands the data. For the expansion format, you can select Partial expansion or Full expansion in the Data Expansion Format section.
-
false (default): Does not expand the data. The data is encapsulated within a single JSON field.
Pass through DDL information
Controls whether to capture Data Definition Language (DDL) operations from the source table, such as
CREATE TABLEandALTER TABLE, and synchronize them to SLS as a log entry.-
true (default): Passes through the DDL information.
-
false: Does not pass through the DDL information.
Source NULL value handling
Specifies the value to write to the destination field when the source field is NULL. By default, this is empty, which preserves the NULL value.
Data Expansion Format
Defines the structure of the business data (the
datafield) when it is written to SLS. This option is visible only when the Expand business data option is set to true. The format you select directly affects how downstream systems consume the logs. For format examples, see Appendix: Data expansion format examples.-
Partial expansion (default): Compatible with the Logtail collection format for MySQL binlog.
-
Full expansion: Flattens all business data fields, including both before and after images of the change, as independent top-level key-value pairs in the data.
-
Step 7: Configure the resource group
Click Configure Resource Group in the upper-right corner of the page to view and switch the resource group used by the current task.
Step 8: Deploy and run the synchronization task
-
After you complete all configurations, click Save to save the task.
-
On the page, find the synchronization task that you created, and click Deploy in the Operation column. If you select Start immediately after deployment during deployment, the task runs immediately after you confirm. Otherwise, you must manually start the task.
NoteData Integration tasks must be deployed to the production environment before they can run. Therefore, you must perform the Publish operation after you create or edit a task for the changes to take effect.
-
Click the Name/ID of the corresponding task in Tasks to view the detailed execution process of the task.
Manage the synchronization task
View task status
After creating the synchronization task, you can view the list of created tasks and their basic information on the synchronization task page. After a task is successfully created, it appears in the task list with the status Running. In the execution overview, the real-time synchronization status is Pending Start, and the resource group is Serverless_Group.
-
In the Operations column, you can Start or Stop the synchronization task. Under More, you can find other actions such as Edit and View.
-
For a running task, you can check the Execution Overview to see its operational status, or click an area in the overview to view details. The Basic Information section on the task details page displays the task ID, data sources, resource group, synchronization solution, and current CU usage. You can switch between the Execution Status, Run Log, Failover, and Resource Usage tabs to monitor the task.
The real-time synchronization task from MySQL to LogHub (SLS) displays real-time statistics, including progress, DDL records, DML records, and alert information.
Rerun a task
In certain scenarios, such as when you need to add or remove tables, or modify destination table schema or table name information, you can click Rerun in the Operations column of the synchronization task. The system synchronizes only the newly added or modified tables. Previously synchronized or unmodified tables are not synchronized again.
-
Click Rerun to rerun the full initialization and real-time synchronization.
-
Edit the task to add or remove tables, save the task, and then deploy it. After the deployment, the Apply Updates button appears in the Operations column. Click Apply Updates to trigger a rerun of the modified task. Only the newly added or modified tables are synchronized. Previously synchronized tables are not synchronized again.
Appendix: Data expansion format examples
-
No expansion
{ "ExecutionTime": 1761017850000, "_db_": "*****", "_event_": "row_update", "_event_time_": 1761017850, "_file_name_": "mysql-bin.*****", "_gtid_": "4a21a3ce-ad7a-11f0-a8f3**********", "_host_": "rm-*********.mysql.rds.aliyuncs.com", "_id_": "176101777********", "_offset_": "265*****", "_table_": "t_parameter", "data": { "updateBefore": { "_old_id": "3", "_old_name": "82174b93-b810-4030-8652-e5c1667d3f72", "_old_value": "+@}8-/XC", "_old_status": "kBdO", "_old_description": "a?!L7{jaH+", "_old_create_time": "2023-12-28 19:03:43", "_old_create_user": "+Zs", "_old_modify_time": "2006-11-26 20:42:31", "_old_modify_user": "brTYGI?jLL" }, "updateAfter": { "id": "3", "name": "82174b93-b810-4030-8652-e5c1667d3f72-tagd", "value": "+@}8-/XC", "status": "kBdO", "description": "a?!L7{jaH+", "create_time": "2023-12-28 19:03:43", "create_user": "+Zs", "modify_time": "2006-11-26 20:42:31", "modify_user": "brTYGI?jLL" } } } -
Partial expansion: Compatible with the Logtail collection format for MySQL binlog
{ "ExecutionTime": 1761017850000, "_db_": "*****", "_event_": "row_update", "_event_time_": 1761017850, "_file_name_": "mysql-bin.*****", "_gtid_": "4a21a3ce-ad7a-11f0-a8f3**********", "_host_": "rm-*********.mysql.rds.aliyuncs.com", "_id_": "176101777********", "_offset_": "265*****", "_table_": "t_parameter", "old_data": { "_old_id": "1", "_old_name": "0e459c1a-c6ce-459b-b374-a161b095c8e9", "_old_value": "Hello", "_old_status": "b", "_old_description": "cw", "_old_create_time": "2007-08-06 16:19:03", "_old_create_user": "!wW4", "_old_modify_time": "2017-04-21 18:21:58", "_old_modify_user": "s" }, "data": { "id": "1", "name": "0e459c1a-c6ce-459b-b374-a161b095c8e9-dsg", "value": "Hello", "status": "b", "description": "cw", "create_time": "2007-08-06 16:19:03", "create_user": "!wW4", "modify_time": "2017-04-21 18:21:58", "modify_user": "s" } } -
Full expansion: All fields are flattened.
{ "ExecutionTime": 1761017850000, "_db_": "****", "_event_": "row_update", "_event_time_": 1761017850, "_file_name_": "mysql-bin.*****", "_gtid_": "4a21a3ce-ad7a-11f0-a8f3**********", "_host_": "rm-*********.mysql.rds.aliyuncs.com", "_id_": "176101777********", "_offset_": "265*****", "_table_": "t_parameter", "_old_create_time": "2024-09-27 15:27:10", "_old_create_user": "o", "_old_description": "LZ[1HsTE", "_old_id": "6", "_old_modify_time": "2008-03-15 08:05:53", "_old_modify_user": "/{=>7_d@0Q", "_old_name": "cf8a671c-4414-45f5-a22c-62c353a6f1ef", "_old_status": "K:HQOX-?gK", "_old_value": "23]sn<t", "create_time": "2024-09-27 15:27:10", "create_user": "o", "description": "LZ[1HsTE", "id": "6", "modify_time": "2008-03-15 08:05:53", "modify_user": "/{=>7_d@0Q", "name": "cf8a671c-4414-45f5-a22c-62c353a6f1efgsdsa", "status": "K:HQOX-?gK", "value": "23]sn<t" }