Configure the MySQL Debezium Connector for Change Data Capture

Configure the MySQL Debezium connector for real-time Change Data Capture (CDC).

Change Data Capture (CDC) enables real-time data streaming. The MySQL Debezium Connector captures database changes and streams them to Apache Kafka. This guide covers connector setup, configuration, and replication user requirements.

Benefits of the MySQL Debezium Connector

The Debezium Connector reads the MySQL binary log (binlog) to capture row-level changes. It supports event-driven architectures and data replication in distributed systems.

Prerequisites for MySQL Debezium Connector Configuration

Verify the following conditions before configuration:

Implementation Guide

Configure the MySQL Database

Enable Binary Logging

Binary logging records database changes to a log file. Debezium captures these changes. The MySQL server must log changes to the binary log to support Debezium tracking.

Update the MySQL configuration to enable binary logging:

SET GLOBAL binlog_format = 'ROW';

SET GLOBAL binlog_row_image = 'FULL';

SET GLOBAL gtid_mode = 'ON';

SET GLOBAL enforce_gtid_consistency = 'ON';

2. Configure Replication User

Configure a MySQL user with replication privileges to enable Debezium to read binary logs. This user captures database changes.

Create the replication user using the following commands:

CREATE USER 'debezium'@'%' IDENTIFIED BY 'password';

GRANT REPLICATION SLAVE, REPLICATION CLIENT ON . TO 'debezium'@'%';

This user enables the connector to read binary logs and capture changes.

3. Configure the Debezium Connector

Configure the Debezium connector to connect to the MySQL database and define capture parameters.

Key configuration properties:

Property Description
database.hostname Hostname of the MySQL server.
database.port MySQL server port (default is 3306 ).
database.user Username with replication privileges (e.g., debezium ).
database.password Password for the above user.
database.server.id Unique identifier for the MySQL server.
database.server.name Logical name for the database server in Kafka topics.
database.include.list Comma-separated list of databases to monitor.
table.include.lis Comma-separated list of tables to monitor.
include.schema.changes Whether to include schema changes ( true or false ).
snapshot.mode Defines the behavior for the initial snapshot.

Connector Connection

  1. Create the Configuration File

Create a JSON or properties file. Include the configuration parameters above.

  1. Deploy the connector. Place the configuration file in the Kafka Connect worker directory. Start the connector using the Kafka Connect REST API.
  2. Verify the connection. Check the Kafka Connect logs. Confirm that the connector is active. Confirm that the connector reads the binary logs.

4. Deploy the Connector

CDC Reliability Practices

  1. Monitor binlog size and retention. Set binlog_expire_logs_seconds to control binary log retention duration.
  2. Assign unique server IDs. Each MySQL server in a distributed setup requires a unique server-id to prevent conflicts.

Summary

Configure the MySQL Debezium Connector to achieve real-time data synchronization. Complete the steps above to establish reliable Change Data Capture (CDC). This setup allows applications to process database changes instantly.

For help building CDC pipelines, see our data engineering services.

Related reading: setting up CDC for Snowflake, PostgreSQL, MySQL and MongoDB and advanced CDC techniques with Snowflake.