MySQL Source Connector for Confluent Cloud

Note

If you are installing the connector locally for Confluent Platform, see JDBC Connector (Source and Sink) for Confluent Platform.

The Kafka Connect MySQL Source connector can capture a snapshot of the existing data in a MySQL database and then monitor and record all subsequent row-level changes to that data. All of the events for each table are recorded in a separate Apache Kafka® topic, where they can be easily consumed by applications and services. Note that deleted records are not captured.

Important

Once this connector moves from Preview to Generally Availability (GA), it will require a subscription for Confluent Cloud commitment for Confluent Cloud Enterprise customers. Without a Confluent Cloud commitment, Confluent Cloud Enterprise customers will not have access to these connectors in GA. Contact your Confluent Account Executive to learn more and to update your subscription, if necessary.

Features

The Confluent Cloud MySQL source connector provides the following features:

  • Insert modes:

    • timestamp mode is enabled when only a timestamp column is specified when you enter database details.

    • timestamp+incrementing mode is enabled when both a timestamp column and incrementing column are specified when you enter database details.

      Important

      A timestamp column must not be nullable.

  • Database authentication: password authentication.

  • Data formats: Avro, JSON. For JSON, the underlying default configuration property is changed to value.converter.schemas.enable=false.

  • Select configuration properties:

    • db.timezone

    • poll.interval.ms

    • batch.max.rows

    • timestamp.delay.interval.ms

    • topic.prefix

    • schema.pattern

      Configuration properties that are not shown in the Confluent Cloud UI use the default values. See JDBC Source Connector Configuration Properties for default values and property definitions.

Refer to Confluent Cloud connector limitations for additional information.

Caution

Preview connectors are not currently supported and are not recommended for production use. For specific connector limitations, see Cloud connector limitations.

Quick Start

Use this quick start to get up and running with the Confluent Cloud MySQL source connector. The quick start shows how to select the connector and configure it to capture a snapshot of the existing data in a MySQL database. It then monitors and records all subsequent row-level changes.

Prerequisites
  • Authorized access to a Confluent Cloud cluster on Amazon Web Services (AWS), Microsoft Azure (Azure), or Google Cloud Platform (GCP).

  • The Confluent Cloud CLI installed and configured for the cluster. See Install and Configure the Confluent Cloud CLI.

  • Public access must be enabled for your database, unless the environment is configured for VPC peering. The example below shows the AWS Management Console when setting up a MySQL database.

    AWS example showing public access for MySQL

    Public access enabled

  • A specific database timezone must be set before creating a MySQL source connector for Azure. See Working with the time zone parameter for more information.

  • Public inbound traffic access (0.0.0.0/0) must be allowed to the VPC where the database is located, unless the environment is configured for VPC peering. The example below shows the AWS Management Console when setting up security group rules for the VPC. See your specific cloud platform documentation for details about how to configure security rules for a VPC.

    AWS example showing security group rules

    Open inbound traffic

  • Confluent Cloud Schema Registry must be enabled if you use Avro.

  • Use one of the following for the Kafka cluster credentials fields:

    • A Confluent Cloud API key and secret. After you have created your cluster, go to Cluster settings > API access > Create Key.
    • A Confluent Cloud service account.

Important

Database table names, topic names, and prefixes:

Before launching this connector, you must create topics in your Confluent Cloud cluster that match your source database table names. For example, if you have a database table named passengers, create a Kafka topic named passengers beforehand. If you want to have a topic prefix, the name of the topic or topics you create must also include the prefix.

You can use the following Confluent Cloud CLI command to create a topic name:

ccloud kafka topic create <prefix-><topic-name>

For example:

ccloud kafka topic create list-passengers

Using the Confluent Cloud GUI

Step 1: Launch your Confluent Cloud cluster.

See the Confluent Cloud Quick Start for installation instructions.

Step 2: Add a connector.

Click Connectors > Add connector.

Add a connector

Step 3: Select your connector.

Click the MySQL Source connector icon.

Step 4: Set up the connection.

Complete the following and click Continue.

Note

  • Make sure you have all your prerequisites completed.
  • An asterisk (*) designates a required entry.
  1. Enter a connector name.

  2. Enter your Kafka Cluster credentials. The credentials are either the API key and secret or the service account API key and secret.

  3. Enter the topic prefix for the database table name. You use this configuration to specify a Kafka topic (or topics), since this connector creates a topic (or topics) directly based on table names from your database.

    Important

    Database table names, topic names, and prefixes:

    Before launching this connector, you must create topics in your Confluent Cloud cluster that match your source database table names. For example, if you have a database table named passengers, create a Kafka topic named passengers beforehand. If you want to have a topic prefix, the name of the topic or topics you create must also include the prefix.

    You can use the following Confluent Cloud CLI command to create a topic name:

    ccloud kafka topic create <prefix-><topic-name>
    

    For example:

    ccloud kafka topic create list-passengers
    
  4. Add the connection details for the database.

    Important

    Do not include jdbc:xxxx:// in the Connection host field. The example below shows a sample host address.

    ../../_images/ccloud-postgresql-source-connect-to-data.png
  5. Add the Database details for your database. Review the following notes for more information about field selections.

    • Enter a Timestamp column name to enable timesamp mode. This mode uses a timestamp (or timestamp-like) column to detect new and modified rows. This assumes the column is updated with each write, and that values are monotonically incrementing, but not necessarily unique.

    • Enter both a Timestamp column name and an Incrementing column name to enable timestamp+incrementing mode. This mode uses two columns, a timestamp column that detects new and modified rows, and a strictly incrementing column which provides a globally unique ID for updates so each row can be assigned a unique stream offset.

    • By default, the connector only detects tables with type TABLE from the source database. Use VIEW for virtual tables created from joining one or more tables. Use ALIAS for tables with a shortened or temporary name.

      Note

      Configuration properties that are not shown in the Confluent Cloud UI use the default values. See JDBC Source Connector Configuration Properties for default values and property definitions.

  6. Add the Connection details for your connection to the database.

  7. Select how your messages are formatted.

  8. Enter the number of tasks in use by the connector. For additional information, see connector limitations.

Step 5: Launch the connector.

Verify the connection details and click Launch.

Launch the connector

Step 6: Check the connector status.

The status for the connector should go from Provisioning to Running. It may take a few minutes.

Check the connector status

Step 7: Check the Kafka topic.

After the connector is running, verify that messages are populating your Kafka topic.

For more information about this connector, see the JDBC Source Connector for Confluent Platform. Note that not all Confluent Platform connector features are provided in the Confluent Cloud connector.

Using the Confluent Cloud CLI

Complete the following steps to set up and run the connector using the Confluent Cloud CLI.

Note

Make sure you have all your prerequisites completed.

Important

Database table names, topic names, and prefixes:

Before launching this connector, you must create topics in your Confluent Cloud cluster that match your source database table names. For example, if you have a database table named passengers, create a Kafka topic named passengers beforehand. If you want to have a topic prefix, the name of the topic or topics you create must also include the prefix.

You can use the following Confluent Cloud CLI command to create a topic name:

ccloud kafka topic create <prefix-><topic-name>

For example:

ccloud kafka topic create list-passengers

Step 1: List the available connectors.

Enter the following command to list available connectors:

ccloud connector-catalog list

Step 2: Show the required connector configuration properties.

Enter the following command to show the required connector properties:

ccloud connector-catalog describe <connector-catalog-name>

For example:

ccloud connector-catalog describe MySqlSource

Example output:

Following are the required configs:
connector.class
name
kafka.api.key
kafka.api.secret
topic.prefix
connection.host
connection.port
connection.user
connection.password
db.name
table.whitelist
timestamp.column.name
data.format
tasks.max

Step 3: Create the connector configuration file.

Create a JSON file that contains the connector configuration properties. The following example shows the required connector properties.

{
    "name" : "confluent-mysql-source",
    "connector.class": "MySqlSource",
    "kafka.api.key": "<my-kafka-api-key>",
    "kafka.api.secret" : "<my-kafka-api-secret>",
    "topic.prefix" : "mysql_",
    "connection.host" : "<my-database-endpoint>",
    "connection.port" : "3306",
    "connection.user" : "<database-username>",
    "connection.password": "<database-password>",
    "db.name": "mysql-test",
    "table.whitelist": "passengers",
    "timestamp.column.name": "created_at",
    "data.format": "JSON",
    "db.timezone": "UCT",
    "tasks.max" : "1"
}

Note the following property definitions:

  • "name": Sets a name for your new connector.

  • "connector.class": Identifies the connector plugin name.

  • "topic.prefix": Used to create the topic name. The connector creates a topic or topics directly based on table names from your database. The Kafka topic name created is a combination of the topic prefix plus the table name.

  • "data.format": Sets the message format. Valid entries are AVRO or JSON.

  • "db.timezone": Identifies the database timezone. This can be any valid database timezone. The default is UTC. For more information, see this list of database timezones.

    Configuration properties that are not listed use the default values. For default values and property definitions, see JDBC Source Connector Configuration Properties.

Step 4: Load the properties file and create the connector.

Enter the following command to load the configuration and start the connector:

ccloud connector create --config <file-name>.json

For example:

ccloud connector create --config mysql-source.json

Example output:

Created connector confluent-mysql-source jtt-ix4dl

Step 5: Check the connector status.

Enter the following command to check the connector status:

ccloud connector list

Example output:

ID          |            Name        | Status  |  Type
+-----------+------------------------+---------+-------+
jtt-ix4dl   | confluent-mysql-source | RUNNING | source

Step 6: Check the Kafka topic.

After the connector is running, verify that messages are populating your Kafka topic.

For additional information about this connector see JDBC Source Connector for Confluent Platform. Note that not all Confluent Platform connector features are provided in the Confluent Cloud connector.

Next Steps

Try out a Confluent Cloud demo.