Skip to main content
Version: 23.1

Create a MySQL (Debezium) Source Connector

You can use a MySQL (Debezium) Source connector to import a stream of changes from MySQL, AmazonRDS, and Amazon Aurora.

Prerequisites

  • A MySQL database that is accessible from the connector instance.
  • A MySQL user exists. This database user for the Debezium connector must have LOCK TABLES privileges. For details, see MySQL Creating a user.
  • A binlog must be enabled for the source MySQL cluster.

Limitations

  • Only JSON or AVRO formats can be used as a a Kafka message key and value format.
  • The MySQL (Debezium) Source connector can work with only a single task at a time.

Create a MySQL (Debezium) Source connector

To create the MySQL (Debezium) Source connector:

  1. In Redpanda Cloud, click Connectors in the navigation menu, and then click Create Connector.

  2. Select Import from MySQL (Debezium).

  3. On the Create Connector page, specify the following required connector configuration options:

    PropertyDescription
    Topic prefixA topic prefix that identifies and provides a namespace for the particular database server/cluster that is capturing changes. The topic prefix should be unique across all other connectors because it is used as a prefix for all Kafka topic names that receive events emitted by this connector. Only alphanumeric characters, hyphens, dots, and underscores are accepted.
    HostnameA resolvable hostname or IP address of the MySQL database server.
    PortInteger port number of the MySQL database server.
    UserName of the MySQL user to be used when connecting to the MySQL database.
    PasswordThe password of the MySQL database user who will be connecting to the MySQL database.
    DatabaseThe name of the database from which the connector will capture changes.
    SSL modeSpecifies whether to use an encrypted connection to the PostgreSQL server. Select disable to use an unencrypted connection. Select require to use a secure, or encrypted connection. If a secure connection cannot be established when required is selected, then the connector fails.
    Kafka message key formatFormat of the key in the Kafka topic.
    Message key JSON contains schemaEnable to specify that the message key contains schema in the schema field.
    Kafka message value formatFormat of the value in the Kafka topic.
    Message value JSON contains schemaEnable to specify that the message value contains schema in the schema field.
    Connector nameGlobally-unique name to use for this connector.
  4. Click Next. Review the connector properties specified, then click Create.

Map data

Use Include databases, Include tables, and Include columns to define data mapping. Alternatively, use Exclude databases, Exclude tables, and Exclude columns.

Following is an example table in db database:

CREATE TABLE IF NOT EXISTS Persons
(
Id int PRIMARY KEY,
FirstName varchar(255),
LastName varchar(255)
);

The table has one record:

INSERT INTO Persons (FirstName, LastName) VALUES (1, 'Winnie', 'the Pooh');

The connector configuration for the table:

column.include.list = db\\.Persons\\.(Id|FirstName|LastName)
table.include.list = db\\.Persons
database.include.list = db
topic.prefix = frommysql

The connector configuration will create the Redpanda topic frommysql.db.Persons.

For Kafka message value format = JSON, the connector produces JSON messages with a schema like the following:

{
"payload": {
"schema": {
// schema definition
},
"payload": {
"before": null,
"after": {
"Id": 1,
"FirstName": "Winnie",
"LastName": "the Pooh"
},
...
}
},
"encoding": "json",
"schemaId": 0
}

For Kafka message value format = AVRO, the connector creates a Schema Registry frommysql.db.Persons-value record and produces messages like the following:

{
"payload": {
"before": null,
"after": {
"mysql.db.Persons.Value": {
"Id": 1,
"FirstName": {
"string": "Winnie"
},
"LastName": {
"string": "the Pooh"
}
}
},
...
},
"encoding": "avro",
"schemaId": 2
}

Test the connection

After the connector is created:

  • Check the connector status and confirm that there are no errors in logs and in Redpanda Console.
  • Review the Redpanda topic to confirm that it contains the expected data.

Troubleshoot

If the connector configuration is invalid, an error appears upon clicking Finish.

  • Topics not created by the connector

    Create the topic manually or let the connector create it by setting (use desired number of partitions and replication factor):

    Topic creation enabled: true
    Topic creation partitions: 1
    Topic creation replication factor: -1

    Or in JSON:

    "topic.creation.enable": true,
    "topic.creation.default.partitions": "1",
    "topic.creation.default.replication.factor": "-1"
  • Connector requires binlog file 'mysql-bin-changelog.257116', but MySQL only has mysql-bin-changelog.257123

    Task threw an uncaught and unrecoverable exception. Task is being killed and will not recover until manually restarted"
    Connector requires binlog file 'mysql-bin-changelog.257116', but MySQL only has mysql-bin-changelog.257123, mysql-bin-changelog.257124, mysql-bin-changelog.257125

    The connector needs a binlog file that was already purged. Change the Snapshot mode property from the default to when_needed.

Additional errors and corrective actions follow.

MessageAction
Unable to connect: Public Key Retrieval is not allowedSet Allow public key retrieval property to true.
Unable to connect: Communications link failureConfirm that Hostname and Port are correct.
Access denied for userConfirm that User and Password credentials are valid.
Caused by: io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException: Invalid schema Invalid namespace: from-mysql.db.Persons; error code: 422The Schema Registry namespace is incorrect. Consider changing the Topic prefix value, remove unallowed characters.

What do you like about this doc?




Optional: Share your email address if we can contact you about your feedback.

Let us know what we do well: