Skip to main content
Connect RisingWave to a MySQL database to ingest data changes in real time using the native MySQL CDC source connector. Need help generating SQL? Use Claude Code or Cursor with the RisingWave MCP server to generate and run SQL interactively. The native MySQL CDC connector supports MySQL versions 5.7, 8.0, and 8.4, as well as compatible databases such as MariaDB and TiDB.

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 the CREATE 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 the CREATE 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 the CREATE 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 the WITH 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 with mysql-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 as FORMAT PLAIN ENCODE JSON so it does not need to be specified.
With the source created, you can create multiple CDC tables that ingest data from different tables in the upstream database without needing to specify the database connection parameters again. For instance, the following CDC table in RisingWave ingests data from table 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.
You can also create another CDC table in RisingWave that ingests data from table t3 in the same database mydb.
To check the progress of backfilling historical data, find the corresponding internal table using the SHOW INTERNAL TABLES command and query from it. For instance, the following SQL query shows the progress of a CDC table named 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.
And then we create a 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:
And this it the output of DESCRIBE supplier;

Auto schema change

PREMIUM FEATUREThis is a premium feature. For a comprehensive overview of all premium features and their usage, please see RisingWave premium features.
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 the ALTER 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.
To enable this feature, set auto.schema.change = 'true' in your MySQL CDC source configuration:
Create a RisingWave table from the MySQL source:
Add columns to the MySQL table and observe the changes in RisingWave:
And this it the output of 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:
Currently, generated columns must appear at the end of the schema definition. If a column from the upstream source appears after a generated column, RisingWave will return an error. For example, the following statement will fail because name, an upstream column, is placed after the generated column next_id:
To avoid errors, ensure that all generated columns are positioned at the end of the schema definition.

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:
  1. Create a table to backfill historical data:
  1. List the internal tables to find the relevant backfill executor state:
Output:
  1. Check the internal state of the backfill executor:
Output:

For real-time data

RisingWave stores source offset in the internal state table of source executor. You can check the current consumed offset by checking this table and comparing it with the upstream database’s log offset. To get the current binlog offset, run this SQL query on upstream MySQL (earlier than 8.4.0):
Then compare the above offset with source offset stored in the state table to determine the CDC progress.