Prerequisites
Before using the native MySQL CDC connector in RisingWave, you need to configure your MySQL database properly.Connect to MySQL
To ingest CDC data from MySQL, you first create a shared source using theCREATE SOURCE statement. This source establishes the connection to the MySQL database. Then, for each upstream table you want to ingest, you define a corresponding table in RisingWave using the CREATE TABLE FROM SOURCE statement.
Create a shared source
Use theCREATE SOURCE statement to create a shared source.
Create a table from the shared source
Next, create a table from the shared source to ingest data from a specific upstream table. In theCREATE TABLE statement, you must define a primary key that matches the upstream table’s primary key and specify the upstream table’s name.
Parameters
Use the these parameters when creating a shared source for MySQL CDC.
Use these parameters when creating a table from a shared source.
For large tables, you can significantly speed up the initial data load by enabling parallelized backfill. Configure this feature using the
backfill.parallelism, backfill_num_rows_per_split, and backfill_as_even_splits parameters.
Debezium parameters
Debezium v2.6 connector configuration properties can also be specified under theWITH clause when creating a table or shared source. Add the prefix debezium. to the connector property you want to include.
For instance, to skip unknown DDL statements, specify the schema.history.internal.skip.unparseable.ddl parameter as debezium.schema.history.internal.skip.unparseable.ddl.
Data format
Data is in Debezium JSON format. Debezium is a log-based CDC tool that can capture row changes from various database management systems such as PostgreSQL, MySQL, and SQL Server and generate events with consistent structures in real time. The MySQL CDC connector in RisingWave supports JSON as the serialization format for Debezium data. The data format does not need to be specified when creating a table withmysql-cdc as the source.
Metadata options
Below are the metadata columns available for MySQL CDC.
For instance, the person table below contains columns for typical personal information. It also includes metadata fields (
database_name, table_name) to provide contextual information about where the data resides within the MySQL database.
Examples
Connect to the upstream database by creating a CDC source using the CREATE SOURCE command and MySQL CDC parameters. The data format is fixed asFORMAT PLAIN ENCODE JSON so it does not need to be specified.
t1 in the database mydb. When specifying the MySQL table name in the FROM clause after the keyword TABLE, the database name must also be specified.
t3 in the same database mydb.
orders_rw.
Data type mapping
The following table shows the corresponding data type in RisingWave that should be specified when creating a source. For details on native RisingWave data types, see Overview of data types. RisingWave data types marked with an asterisk indicate that while there is no corresponding RisingWave data type, the ingested data can still be consumed as the listed type.
Please be aware that the range of specific values varies among MySQL types and RisingWave types. Refer to the table below for detailed information.
Use dbt to ingest data from MySQL CDC
Here is an example of how to use dbt to ingest data from MySQL CDC. In this dbt example,source and table_with_connector models will be used. For more details about these two models, please refer to Use dbt for data transformations.
First, we create a source model mysql_mydb.sql.
table_with_connector model t1_rw.sql.
Automatically map upstream table schema
RisingWave supports automatically mapping the upstream table schema when creating a CDC table from a MySQL CDC source. Instead of defining columns individually, you can use* when creating a table to ingest all columns from the source table. Note that * cannot be used if other columns are specified in the table creation process.
Below is an example to create a table that ingests all columns from the upstream table from the MySQL database:
DESCRIBE supplier;
Auto schema change
RisingWave supports auto schema changes in MySQL CDC. It ensures that your RisingWave pipeline stays synchronized with any schema changes in the source database, reducing the need for manual updates and preventing inconsistencies. Currently, RisingWave supports theALTER TABLE command with the following operations, and we plan to add support for additional DDL operations in future releases.
ADD COLUMN [DEFAULT expr]: Allows you to add a new column to an existing table. Only constant value expressions are supported for the default value.DROP COLUMN: Allows you to remove an existing column from a table.
auto.schema.change = 'true' in your MySQL CDC source configuration:
DESCRIBE rw_customers;
Expression as a column
RisingWave allows users to define expressions as table columns. For example, in the SQL statement below,next_id is not a column from the source MySQL table. Instead, it is a generated column that RisingWave computes dynamically while ingesting data. The value of next_id for each row is always equal to id + 1:
name, an upstream column, is placed after the generated column next_id:
Monitor the progress of direct CDC
To observe the progress of direct CDC for MySQL, use the following methods:For historical data
Historical data needs to be backfilled into the table. You can check the internal state of the backfill executor as follows:- Create a table to backfill historical data:
- List the internal tables to find the relevant backfill executor state:
- Check the internal state of the backfill executor: