Create a Debezium source connector from MySQL to Apache Kafka®
The MySQL Debezium source connector extracts changes committed to the database binary log (binlog) and writes them to an Apache Kafka® topic in a standard format, allowing them to be transformed and read by multiple consumers.
Breaking changes in Debezium 2.5
Debezium version 2.5 introduces significant changes to the connector's configuration and behavior. New setups default to version 2.5, while existing setups using version 1.9 remain on that version for stability. Test configurations with version 2.5 before upgrading. For help with upgrades or queries, contact Aiven support.
Schema versioning
Database table schemas evolve by adding, modifying, or removing columns. The MySQL
Debezium source connector tracks schema changes by storing them in a separate
history
topic, which you can set up with dedicated history.*
configuration parameters.
The MySQL Debezium source connector's history.*
parameters are not visible in the list
of configuration options in the Aiven
Console. However, you can insert or modify them by editing
the JSON configuration in the Connector configuration section.
Prerequisites
Before configuring a Debezium source connector for MySQL, ensure you have:
- An Aiven for Apache Kafka service with Apache Kafka Connect enabled, or
- A dedicated Aiven for Apache Kafka Connect cluster.
Required database details
Gather the following details about your MySQL database:
You can view the full set of available parameters and configuration options in the connector's documentation.
MYSQL_HOST
: The database hostname.MYSQL_PORT
: The database port.MYSQL_USER
: The database user to connect.MYSQL_PASSWORD
: The database password for theMYSQL_USER
.MYSQL_DATABASE_NAME
: The database name.SSL_MODE
: The SSL mode.MYSQL_TABLES
: The list of database tables to be included in Apache Kafka. Format the list asschema_name1.table_name1,schema_name2.table_name2
.APACHE_KAFKA_HOST
: The hostname of the Apache Kafka service, needed when storing the schema definition changes.APACHE_KAFKA_PORT
: The port of the Apache Kafka service, needed when storing the schema definition changes.SCHEMA_REGISTRY_PORT
: The Apache Kafka's schema registry port is only needed when using Avro as a data format.SCHEMA_REGISTRY_USER
: The Apache Kafka's schema registry username is only needed when using Avro as a data format.SCHEMA_REGISTRY_PASSWORD
: The Apache Kafka's schema registry user password is only needed when using Avro as a data format.
If you're using Aiven for MySQL and Aiven for Apache Kafka, find the
required details on the service's Overview page in the
Aiven console or by running the
avn service get
command
via the Aiven CLI.
Create an Apache Kafka Connect configuration file
Create a file named debezium_source_mysql.json
with the following connector
configurations. This file is optional but helps you keep your settings organized and
makes it easier to copy and paste them into the Aiven Console later.
- Version 2.5
- Version 1.9
{
"name":"CONNECTOR_NAME",
"connector.class": "io.debezium.connector.mysql.MySqlConnector",
"database.hostname": "MYSQL_HOST",
"database.port": "MYSQL_PORT",
"database.user": "MYSQL_USER",
"database.password": "MYSQL_PASSWORD",
"database.dbname": "MYSQL_DATABASE_NAME",
"database.ssl.mode": "SSL_MODE",
"database.server.id": "UNIQUE_ID",
"topic.prefix": "KAFKA_TOPIC_PREFIX",
"table.include.list": "MYSQL_TABLES",
"tasks.max":"NR_TASKS",
"key.converter": "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url": "https://APACHE_KAFKA_HOST:SCHEMA_REGISTRY_PORT",
"key.converter.basic.auth.credentials.source": "USER_INFO",
"key.converter.schema.registry.basic.auth.user.info": "SCHEMA_REGISTRY_USER:SCHEMA_REGISTRY_PASSWORD",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "https://APACHE_KAFKA_HOST:SCHEMA_REGISTRY_PORT",
"value.converter.basic.auth.credentials.source": "USER_INFO",
"value.converter.schema.registry.basic.auth.user.info": "SCHEMA_REGISTRY_USER:SCHEMA_REGISTRY_PASSWORD",
"schema.history.internal.kafka.topic": "HISTORY_TOPIC_NAME",
"schema.history.internal.kafka.bootstrap.servers": "APACHE_KAFKA_HOST:APACHE_KAFKA_PORT",
"schema.history.internal.producer.security.protocol": "SSL",
"schema.history.internal.producer.ssl.keystore.type": "PKCS12",
"schema.history.internal.producer.ssl.keystore.location": "/run/aiven/keys/public.keystore.p12",
"schema.history.internal.producer.ssl.keystore.password": "password",
"schema.history.internal.producer.ssl.truststore.location": "/run/aiven/keys/public.truststore.jks",
"schema.history.internal.producer.ssl.truststore.password": "password",
"schema.history.internal.producer.ssl.key.password": "password",
"schema.history.internal.consumer.security.protocol": "SSL",
"schema.history.internal.consumer.ssl.keystore.type": "PKCS12",
"schema.history.internal.consumer.ssl.keystore.location": "/run/aiven/keys/public.keystore.p12",
"schema.history.internal.consumer.ssl.keystore.password": "password",
"schema.history.internal.consumer.ssl.truststore.location": "/run/aiven/keys/public.truststore.jks",
"schema.history.internal.consumer.ssl.truststore.password": "password",
"schema.history.internal.consumer.ssl.key.password": "password",
"include.schema.changes": "true"
}
Parameters:
-
name
: The connector name. ReplaceCONNECTOR_NAME
with the connector name. -
database.hostname
,database.port
,database.dbname
,database.ssl.mode
,database.user
,database.password
,table.include.list
: Source database parameters collected in the prerequisite phase. -
database.server.id
: The logical name of the database server. This should be a unique ID. -
topic.prefix
: The prefix to be used for the Apache Kafka topic names. -
tasks.max
: Maximum number of tasks to execute in parallel. ReplaceNR_TASKS
with the number of parallel tasks based on the number of tables. -
schema.history.internal.kafka.topic
: The name of the Apache Kafka topic that contains the history of schema changes. -
schema.history.internal.kafka.bootstrap.servers
: The address of the Apache Kafka service that stores schema definition changes. -
schema.history.internal.producer
andschema.history.internal.consumer
: Parameters related to SSL configuration for Apache Kafka connections.warningThe values defined for each
schema.history.internal.producer
andschema.history.internal.consumer
parameters are already set to work with the predefined truststore and keystore created in the Aiven for Apache Kafka nodes. Modifying these values is not recommended. -
key.converter
andvalue.converter
: Defines the message data format in the Apache Kafka topic. Avro format is used in this example. -
include.schema.changes
: Whether to include changes to the schema itself.noteThe
key.converter
andvalue.converter
sections are only needed when pushing data in Avro format. Otherwise, messages default to JSON format.The
USER_INFO
is not a placeholder and does not require any parameter substitution.
{
"name":"CONNECTOR_NAME",
"connector.class": "io.debezium.connector.mysql.MySqlConnector",
"database.hostname": "MYSQL_HOST",
"database.port": "MYSQL_PORT",
"database.user": "MYSQL_USER",
"database.password": "MYSQL_PASSWORD",
"database.dbname": "MYSQL_DATABASE_NAME",
"database.ssl.mode": "SSL_MODE",
"database.server.name": "KAFKA_TOPIC_PREFIX",
"table.include.list": "MYSQL_TABLES",
"tasks.max":"NR_TASKS",
"key.converter": "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url": "https://APACHE_KAFKA_HOST:SCHEMA_REGISTRY_PORT",
"key.converter.basic.auth.credentials.source": "USER_INFO",
"key.converter.schema.registry.basic.auth.user.info": "SCHEMA_REGISTRY_USER:SCHEMA_REGISTRY_PASSWORD",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "https://APACHE_KAFKA_HOST:SCHEMA_REGISTRY_PORT",
"value.converter.basic.auth.credentials.source": "USER_INFO",
"value.converter.schema.registry.basic.auth.user.info": "SCHEMA_REGISTRY_USER:SCHEMA_REGISTRY_PASSWORD",
"database.history.kafka.topic": "HISTORY_TOPIC_NAME",
"database.history.kafka.bootstrap.servers": "APACHE_KAFKA_HOST:APACHE_KAFKA_PORT",
"database.history.producer.security.protocol": "SSL",
"database.history.producer.ssl.keystore.type": "PKCS12",
"database.history.producer.ssl.keystore.location": "/run/aiven/keys/public.keystore.p12",
"database.history.producer.ssl.keystore.password": "password",
"database.history.producer.ssl.truststore.location": "/run/aiven/keys/public.truststore.jks",
"database.history.producer.ssl.truststore.password": "password",
"database.history.producer.ssl.key.password": "password",
"database.history.consumer.security.protocol": "SSL",
"database.history.consumer.ssl.keystore.type": "PKCS12",
"database.history.consumer.ssl.keystore.location": "/run/aiven/keys/public.keystore.p12",
"database.history.consumer.ssl.keystore.password": "password",
"database.history.consumer.ssl.truststore.location": "/run/aiven/keys/public.truststore.jks",
"database.history.consumer.ssl.truststore.password": "password",
"database.history.consumer.ssl.key.password": "password",
"include.schema.changes": "true"
}
Parameters:
-
name
: The connector name. ReplaceCONNECTOR_NAME
with the connector name. -
database.hostname
,database.port
,database.dbname
,database.ssl.mode
,database.user
,database.password
,table.include.list
: Source database parameters collected in the prerequisite phase. -
database.server.name
: The logical name of the database, which determines the prefix used for Apache Kafka topic names. The resulting topic name is a combination of thedatabase.server.name
and the table name. -
tasks.max
: Maximum number of tasks to execute in parallel. By default this is 1, the connector can use at most 1 task for each source table defined. ReplaceNR_TASKS
with the amount of parallel task based on the number of tables. -
database.history.kafka.topic
: The name of the Apache Kafka topic that contains the history of schema changes. -
database.history.kafka.bootstrap.servers
: Directs to the Aiven for Apache Kafka service that runs the connector and stores schema definition changes. -
database.history.producer
anddatabase.history.consumer
: Refers to truststores and keystores pre-created on the Aiven for Apache Kafka node to handle SSL authentication.warningThe values defined for each
database.history.producer
anddatabase.history.consumer
parameters are already set to work with the predefined truststore and keystore created in the Aiven for Apache Kafka nodes. Modifying these values is not recommended. -
key.converter
andvalue.converter
: Defines the messages data format in the Apache Kafka topic. Theio.confluent.connect.avro.AvroConverter
converter pushes messages in Avro format. To store the message schemas, Aiven's Karapace schema registry is used, specified by theschema.registry.url
parameter and related credentials. -
include.schema.changes
: Whether to include changes to the schema itself.noteThe
key.converter
andvalue.converter
sections are only needed when pushing data in Avro format. Otherwise, messages default to JSON format.The
USER_INFO
is not a placeholder and does not require any parameter substitution.
Setup a MySQL Debezium source connector
- Aiven Console
- Aiven CLI
-
Access the Aiven Console.
-
Select your Aiven for Apache Kafka® or Aiven for Apache Kafka Connect® service.
-
Click Connectors.
-
Click Create connector if Apache Kafka Connect is already enabled on the service. If not, click Enable connector on this service.
Alternatively, to enable connectors:
- Click Service settings in the sidebar.
- In the Service management section, click Actions > Enable Kafka connect.
-
In the source connectors, click Get started on Debezium - MySQL.
-
On the Create Debezium - MySQL Connector page, click the Common tab, find the Connector configuration text box, and click Edit.
-
Paste the connector configuration stored in the
debezium_source_mysql.json
file into the editor. -
Click Apply.
noteThe Aiven Console reads the configuration file and automatically populates the relevant UI fields. You can view and modify these fields across different tabs. Any changes you make in these fields are reflected in the JSON format within the Connector configuration text box.
-
Click Create connector.
tipWith Aiven for Apache Kafka, topics are not created automatically. You have two options:
- Manually create topics using the naming pattern:
database.server.name.schema_name.table_name
. - Enable auto-creation for Apache Kafka topics.
- Manually create topics using the naming pattern:
-
Verify the connector status on the Connectors page.
Verify that data from the MySQL dataset is present in the target Apache Kafka topic.
The topic name is a concatenation of the database and table name. To modify the
target table name, use the Apache Kafka Connect RegexRouter
transformation.
To create a Debezium source connector from MySQL to Apache Kafka using the Aiven CLI, run the following command:
avn service connector create SERVICE_NAME @debezium_source_mysql.json
Parameters:
SERVICE_NAME
: The name of your Aiven for Apache Kafka service.@debezium_source_mysql.json
: This denotes the path to your JSON configuration file.