MySQL CDC with SQL Mapping
In VeloDB Cloud Core 26.1.1 and later, use INSERT INTO ... SELECT ... FROM cdc_stream(...) in a Streaming Job to load a single MySQL table into an existing Unique Key table. The job commits the target write and its source offset together for exactly-once processing.
For a group of tables that should mirror their source schemas, see MySQL CDC with Auto Table Creation.
SQL continuous load is experimental. Check Continuous Load Overview for warehouse availability.
Prerequisites
- Connect to your warehouse using a SQL user with
LOAD_PRIVon the target table. Select a running compute cluster. - Create a target Unique Key table with columns compatible with the selected source columns. Preserve the MySQL primary key when mapping columns. See MySQL data type mapping.
- Configure row-based binary logging with full row images and a dedicated MySQL replication account. The warehouse must be able to reach the source host and use the specified JDBC driver. See MySQL connection prerequisites.
1. Create the job
The following example synchronizes shop.orders to analytics.orders. Both tables use order_id as their key. The example maps the MySQL column amount to the target column order_total and propagates deletes using the hidden delete-sign column. Use Core 26.1.2 or later for this example. Replace the connection settings and table and column names with your own.
USE analytics;
CREATE JOB mysql_orders_mapping
ON STREAMING
DO
INSERT INTO analytics.orders (order_id, order_total, __DORIS_DELETE_SIGN__)
SELECT order_id, amount, __DORIS_DELETE_SIGN__
FROM cdc_stream(
"type" = "mysql",
"jdbc_url" = "jdbc:mysql://mysql.example.com:3306",
"driver_url" = "mysql-connector-j-8.3.0.jar",
"driver_class" = "com.mysql.cj.jdbc.Driver",
"user" = "cdc_reader",
"password" = "<source-password>",
"database" = "shop",
"table" = "orders",
"offset" = "initial",
"include_delete_sign" = "true"
);
The initial offset loads existing rows first. The job then reads new changes from the MySQL binary log. Use latest to start with changes that occur after the job starts.
2. Verify synchronization
SELECT Name, Status, CurrentOffset, ErrorMsg
FROM jobs("type" = "insert")
WHERE Name = 'mysql_orders_mapping' AND ExecuteType = 'STREAMING';
Check that the job is RUNNING. Verify that an insert, update, and delete on a test row in the source are reflected in the warehouse. To pause, resume, inspect individual tasks, or remove a job, see Continuous Load Overview.
Source settings
| Property | Description |
|---|---|
type | Set to mysql. |
jdbc_url, driver_url, driver_class | MySQL JDBC URL, a driver package name or approved HTTPS URL accessible to the warehouse, and JDBC driver class. |
user, password | Credentials for the MySQL replication account. |
database, table | MySQL source database and table. |
offset | initial takes a snapshot before reading changes. Set latest to read only new changes. This property is required. |
snapshot_split_size | Number of rows per split during a full snapshot. The default is 40,960 in Core 26.1.2 and later. |
snapshot_parallelism | Maximum number of splits per snapshot task. Defaults to 1 for SQL Mapping Sync. |
include_delete_sign | Expose the delete marker in the function output. Defaults to false. To propagate deletes, set to true and explicitly map __DORIS_DELETE_SIGN__ on both sides of the insert. |
SQL Mapping Sync uses the target schema you maintain. Before changing a source column referenced in the query, check that the target column and SQL mapping remain compatible.