# Set Up MySQL CDC with Debezium and Redpanda

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [labs-full.txt](https://docs.redpanda.com/labs-full.txt)

---
title: Set Up MySQL CDC with Debezium and Redpanda
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: cdc-mysql-json
page-component-name: labs
page-version: master
page-component-version: master
page-component-title: Labs
page-relative-src-path: cdc-mysql-json.adoc
page-edit-url: https://github.com/redpanda-data/redpanda-labs/edit/main/docs/modules/docker-compose/pages/cdc-mysql-json.adoc
description: Use Debezium to capture the changes made to a MySQL database in real time and stream them to Redpanda.
page-git-created-date: "2025-05-06"
page-git-modified-date: "2025-05-06"
---

<!-- Source: https://docs.redpanda.com/labs/docker-compose/cdc-mysql-json.md -->

This example demonstrates how to use Debezium to capture the changes made to MySQL in real time and stream them to Redpanda.

This ready-to-run Docker Compose setup contains the following containers:

-   `mysql` container with the `pandashop` database, containing a single table, `orders`

-   `debezium` container capturing changes made to the `orders` table in real time.

-   `redpanda` container to ingest change data streams produced by `debezium`


For more information about the `pandashop` database schema, see the `/data/mysql_bootstrap.sql` file.

![Example architecture](https://docs.redpanda.com/labs/docker-compose/_images/mysql-architecture.png)

## [](#prerequisites)Prerequisites

You must have [Docker and Docker Compose](https://docs.docker.com/compose/install/) installed on your host machine.

This lab is intended for Linux and macOS users. If you are using Windows, you must use the Windows Subsystem for Linux (WSL) to run the commands in this lab.

## [](#run-the-lab)Run the lab

1.  Clone this repository:

    ```bash
    git clone https://github.com/redpanda-data/redpanda-labs.git
    ```

2.  Change into the `docker-compose/cdc/mysql-json/` directory:

    ```bash
    cd redpanda-labs/docker-compose/cdc/mysql-json
    ```

3.  Set the `REDPANDA_VERSION` environment variable to the version of Redpanda that you want to run. For all available versions, see the [GitHub releases](https://github.com/redpanda-data/redpanda/releases).

    For example:

    ```bash
    export REDPANDA_VERSION=v26.1.9
    ```

4.  Run the following in the directory where you saved the Docker Compose file:

    ```bash
    docker compose up -d
    ```

    When the `mysql` container starts, the `/data/mysql_bootstrap.sql` file creates the `pandashop` database and the `orders` table, followed by seeding the \` orders\` table with a few records.

5.  Log into MySQL:

    ```sql
    docker compose exec mysql mysql -u mysqluser -p
    ```

    Provide `mysqlpw` as the password when prompted.

6.  Check the content inside the `orders` table:

    ```sql
    use pandashop;
    show tables;
    select * from orders;
    ```

    This is your source table.

7.  Exit MySQL:

    ```bash
    exit
    ```

8.  While Debezium is up and running, create a source connector configuration to extract change data feeds from MySQL.

    ```bash
    docker compose exec debezium curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" localhost:8083/connectors/ -d '
     {
      "name": "mysql-connector",
      "config": {
        "connector.class": "io.debezium.connector.mysql.MySqlConnector",
        "tasks.max": "1",
        "database.hostname": "mysql",
        "database.port": "3306",
        "database.user": "debezium",
        "database.password": "dbz",
        "database.server.id": "184054",
        "topic.prefix": "dbz",
        "database.include.list": "pandashop",
        "schema.history.internal.kafka.bootstrap.servers": "redpanda:9092",
        "schema.history.internal.kafka.topic": "schemahistory.pandashop"
      }
    }'
    ```

    You should see the following in the output:

    HTTP/1.1 201 Created
    Date: Mon, 12 Feb 2024 16:37:09 GMT
    Location: http://localhost:8083/connectors/mysql-connector
    Content-Type: application/json
    Content-Length: 489
    Server: Jetty(9.4.51.v20230217)

    The `database.*` configurations specify the connectivity details to `mysql` container. The parameter, `schema.history.internal.kafka.bootstrap.servers` points to the `redpanda` broker the connector uses to write and recover DDL statements to the database schema history topic.

9.  Wait a minute or two until the connector gets deployed inside Debezium and creates the initial snapshot of change log topics in Redpanda.

10.  Check the list of change log topics in `redpanda` by running:

     ```bash
     docker compose exec redpanda rpk topic list
     ```

     The output should contain two topics with the prefix `dbz.*` specified in the connector configuration. The topic `dbz.pandashop.orders` holds the initial snapshot of change log events streamed from `orders` table.

     NAME                     PARTITIONS  REPLICAS
     connect-status           5           1
     connect\_configs          1           1
     connect\_offsets          25          1
     dbz                      1           1
     dbz.pandashop.orders     1           1
     schemahistory.pandashop  1           1

11.  Monitor for change events by consuming the `dbz.pandashop.orders` topic:

     ```bash
     docker compose exec redpanda rpk topic consume dbz.pandashop.orders
     ```

12.  While the consumer is running, open another terminal to insert a record to the `orders` table.

     ```bash
     export REDPANDA_VERSION=v26.1.9
     docker compose exec mysql mysql -u mysqluser -p
     ```

     Provide `mysqlpw` as the password when prompted.

13.  Insert the following record:

     ```sql
     use pandashop;
     INSERT INTO orders (customer_id, total) values (5, 500);
     ```


This will trigger a change event in Debezium, immediately publishing it to `dbz.pandashop.orders` Redpanda topic, causing the consumer to display a new event in the console. That proves the end-to-end functionality of your CDC pipeline.

## [](#clean-up)Clean up

To shut down and delete the containers along with all your cluster data:

```bash
docker compose down -v
```

## [](#next-steps)Next steps

Now that you have change log events ingested into Redpanda. You process change log events to enable use cases such as:

-   Database replication

-   Stream processing applications

-   Streaming ETL pipelines

-   Update caches

-   Event-driven Microservices