MySQL Source (JDBC) 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 for Confluent Cloud can obtain a snapshot of the existing data in a MySQL database and then monitor and record all subsequent row-level changes to that data. The connector supports Avro, JSON Schema, Protobuf, or JSON (schemaless) output data formats. All of the events for each table are recorded in a separate Apache Kafka® topic. The events can then be easily consumed by applications and services. Note that deleted records are not captured.

Important

If you are still on Confluent Cloud Enterprise, please contact your Confluent Account Executive for more information about using this connector.

Features

The MySQL Source connector provides the following features:

  • Topics created automatically: The connector automatically creates Kafka topics using the naming convention: <topic.prefix><tableName>. The tables are created with the properties: topic.creation.default.partitions=1 and topic.creation.default.replication.factor=3.

  • 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: Uses password authentication.

  • SSL support: Supports one-way SSL.

  • Data formats: The connector supports Avro, JSON Schema, Protobuf, or JSON (schemaless) output data. Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).

  • Select configuration properties:

    • db.timezone
    • poll.interval.ms
    • batch.max.rows
    • timestamp.delay.interval.ms
    • topic.prefix
    • schema.pattern

See the MySQL Source configuration properties for property values and definitions. See Confluent Cloud connector limitations for additional information.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

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.

  • The connector automatically creates Kafka topics using the naming convention: <prefix>.<table-name>. The tables are created with the properties: topic.creation.default.partitions=1 and topic.creation.default.replication.factor=3. If you want to create topics with specific settings, please create the topics before running this connector.

  • Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).

  • Public access may be required for your database. See Internet Access to Resources for details. The example below shows the AWS Management Console when setting up a MySQL database.

    AWS example showing public access for MySQL

    Public access enabled

  • For networking considerations, see Internet access to resources. To use static egress IPs, see Static Egress IP Addresses.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.

  • A timestamp column must not be nullable.

    AWS example showing security group rules

    Open inbound traffic

  • 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.

  • Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).

  • Kafka cluster credentials. You can use one of the following ways to get credentials:
    • Create a Confluent Cloud API key and secret. To create a key and secret, you can use the Confluent Cloud CLI or you can autogenerate the API key and secret directly in the Cloud Console when setting up the connector.
    • Create a Confluent Cloud service account for the connector. Make sure to review the ACL entries required in the service account documentation. Some connectors have specific ACL requirements.

Using the Confluent Cloud Console

Step 1: Launch your Confluent Cloud cluster.

See the Quick Start for Apache Kafka using Confluent Cloud for installation instructions.

Step 2: Add a connector.

In the left navigation menu, click Data integration, and then click Connectors. If you already have connectors in your cluster, click + Add connector.

Step 3: Select your connector.

Click the MySQL Source connector icon.

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 a topic prefix. The connector automatically creates Kafka topics using the naming convention: <prefix>.<table-name>. The tables are created with the properties: topic.creation.default.partitions=1 and topic.creation.default.replication.factor=3. If you want to create topics with specific settings, please create the topics before running this connector.

  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

    Note that the default option prefer is enabled for SSL mode if no option is selected. When prefer is enabled, the connector attempts to use an encrypted connection to the database server. Options include:

    • prefer and require: The connector uses a secure (encrypted) connection. The connector fails if a secure connection cannot be established. These modes do not do Certification Authority (CA) validation.
    • verify-ca: This option is similar to require, but additionally verifies the server TLS certificate against the configured Certificate Authority (CA) certificates. Fails if no valid matching CA certificates are found.
    • verify-full: similar to verify-ca, but also verifies that the server certificate matches the host to which the connection is attempted.
    • You use the Trust store button to upload the truststore file that contains the CA information. You must add the Truststore password.
  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.
    • If you define a schema pattern in your database, you need to enter the Schema pattern to fetch table metadata from the database. "" retrieves table metadata for tables not using a schema. null (default) indicates that the schema name is not used to narrow the search and that all table metadata is fetched, regardless of the schema.
  6. Select an Output message format (data coming from the connector): AVRO, JSON_SR (JSON Schema), PROTOBUF, or JSON (schemaless). A valid schema must be available in Schema Registry to use a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).

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

  8. Transforms and Predicates: See the Single Message Transforms (SMT) documentation for details.

See the MySQL Source configuration properties for property values and definitions.

Step 5: Launch the connector.

Verify the connection details by previewing the running configuration. Once you’ve validated that the properties are configured to your satisfaction, click Launch.

Tip

For information about previewing your connector output, see Connector Data Previews.

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 and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud ksqlDB, see the Cloud ETL Demo. This example also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.

../_images/topology.png

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.

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
ssl.mode
table.whitelist
timestamp.column.name
output.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>",
    "ssl.mode": "prefer",
    "db.name": "mysql-test",
    "table.whitelist": "passengers",
    "timestamp.column.name": "created_at",
    "output.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": Enter a topic prefix. The connector automatically creates Kafka topics using the naming convention: <prefix>.<table-name>. The tables are created with the properties: topic.creation.default.partitions=1 and topic.creation.default.replication.factor=3. If you want to create topics with specific settings, please create the topics before running this connector.

  • The following provides more information about how to use the ssl.mode property:

    • The default option prefer is enabled if ssl.mode is not added to the connector configuration. When prefer is enabled, the connector attempts to use an encrypted connection to the database server.
    • prefer and require: use a secure (encrypted) connection. The connector fails if a secure connection cannot be established. These modes do not do Certification Authority (CA) validation.
    • verify-ca: similar to require, but also verifies the server TLS certificate against the configured Certificate Authority (CA) certificates. Fails if no valid matching CA certificates are found.
    • verify-full: similar to verify-ca, but also verifies that the server certificate matches the host to which the connection is attempted.

    If you choose verify-ca or verify-full, use the property ssl.rootcertfile and add the contents of the text certificate file for the property value. For example, "ssl.rootcertfile": "<certificate-text>".

  • The following provides more information about how to use the timestamp.column.name and incrementing.column.name properties.

    • Enter a timestamp.column.name to enable timestamp 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 table.types with type TABLE from the source database. Enter VIEW for virtual tables created from joining one or more tables. Enter ALIAS for tables with a shortened or temporary name.
  • If you define a schema pattern in your database, you need to enter the schema.pattern property to fetch table metadata from the database. "" retrieves table metadata for tables not using a schema. null (default) indicates that the schema name is not used to narrow the search and that all table metadata is fetched, regardless of the schema.

  • "output.data.format": Sets the output message format (data coming from the connector). Valid entries are AVRO, JSON_SR, PROTOBUF, or JSON. You must have Confluent Cloud Schema Registry configured if using a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).

  • "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.

Single Message Transforms: See the Single Message Transforms (SMT) documentation for details about adding SMTs using the CLI.

See the MySQL Source configuration properties for property values and definitions.

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 lcc-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
+-----------+------------------------+---------+-------+
lcc-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 more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Configuration Properties

The following connector configuration properties can be used with the MySQL Source connector for Confluent Cloud.

topic.prefix

Prefix to prepend to table names to generate the name of the Apache Kafka® topic to publish data to, or in the case of a custom query, the full name of the topic to publish to.

  • Type: string
  • Importance: high
connection.host

The host URL address. For example, 192.136.114.86.

  • Type: string
  • Importance: high
connection.port

The host port to connect to. For example, 3306.

  • Type: int
  • Importance: high
connection.user

Database connection user.

  • Type: string
  • Importance: high
connection.password

Database connection user password.

  • Type: password
  • Importance: high
db.name

Database name.

  • Type: string
  • Importance: high
ssl.mode

The default option prefer is enabled if ssl.mode is not added to the connector configuration. When prefer is enabled, the connector attempts to use an encrypted connection to the database server. prefer and require: use a secure (encrypted) connection. The connector fails if a secure connection cannot be established. These modes do not do Certification Authority (CA) validation. verify-ca: similar to require, but also verifies the server TLS certificate against the configured Certificate Authority (CA) certificates. Fails if no valid matching CA certificates are found. verify-full: similar to verify-ca, but also verifies that the server certificate matches the host to which the connection is attempted.

  • Type: string
  • Default: prefer
  • Importance: high
ssl.truststorefile
The file containing the server CA certificate. This is required if using verify-ca or verify-full SSL mode. You must encode the binary truststore file in base64, take the encoded string, add the data:text/plain;base64 prefix, and then specify the entire string as the property entry. For example: "ssl.truststorefile" : "data:text/plain;base64,/u3+7QAAAAIAAAACAAAAAQAGY2xpZ...==".
ssl.truststorepassword

The password for the truststore file.

  • Type: password
  • Importance: low
table.whitelist

List of tables from which to get data. Use a comma-separated list to specify multiple tables. For example "table.whitelist" : "User, Address, Email".

  • Type: string
  • Importance: low
timestamp.column.name

Comma-separated list of one or more timestamp columns used to detect new or modified rows using the COALESCE SQL function. Rows whose first non-null timestamp value is greater than the largest previous timestamp value are discovered with each poll. At least one column should not be nullable.

  • Type: string
  • Default: “”
  • Importance: medium
incrementing.column.name

The name of the strictly incrementing column to use when detecting new rows. Any empty value indicates the column should be autodetected by looking for an auto-incrementing column. This column may not be nullable.

  • Type: string
  • Default: “”
  • Importance: medium
table.types

By default, this connector only detects tables with type TABLE from the source Database. This config allows a comma-separated list of table types to extract. Accepts TABLE, VIEW, or ALIAS as property values.

  • Type: list
  • Default: TABLE
  • Importance: low
schema.pattern

Schema pattern to fetch table metadata from the database. "" retrieves table metadata for tables not using a schema. null (default) indicates that the schema name is not used to narrow the search and that all table metadata is fetched, regardless of the schema.

  • Type: string
  • Default: null
  • Importance: high
db.timezone

Name of the database timezone to use with the connector, when querying with time-based criteria. Defaults to UTC.

  • Type: string
  • Default: UTC
  • Valid values: Any valid JDK time zone
  • Importance: medium
numeric.mapping

Map NUMERIC values by precision and optionally scale to integral or decimal types. Use none if all NUMERIC columns are to be represented by Connect’s DECIMAL logical type. Use best_fit if NUMERIC columns should be cast to Connect’s INT8, INT16, INT32, INT64, or FLOAT64 based upon the column’s precision and scale. This option may still represent the NUMERIC value as Connect DECIMAL if it cannot be cast to a native type without losing precision. For example, a NUMERIC(20) type with precision 20 would not be able to fit in a native INT64 without overflowing and thus would be retained as DECIMAL. The none option is the default, but may lead to serialization issues with Avro since the Connect DECIMAL type is mapped to its binary representation. Typically, best_fit should be used since it maps to the most appropriate primitive type.

  • Type: string
  • Default: null
  • Valid Values: [none, precision_only, best_fit]
  • Importance: low
poll.interval.ms

Internal time in milliseconds to poll for new data in each table.

  • Type: int
  • Default: 5000
  • Importance: high
batch.max.rows

Maximum number of rows to include in a single batch, when polling for new data. This setting can be used to limit the amount of data buffered internally in the connector.

  • Type: int
  • Default: 100
  • Importance: low
timestamp.delay.interval.ms

How long to wait after a row with a given timestamp appears until that data is included in the result. You may choose to use timestamp delay to allow transactions having an earlier timestamp to complete first. The first time it runs, the connector fetches all available records (that is, starting at timestamp 0) up to the current time, minus the timestamp delay. After that, every time the connector fetches records, it fetches data from the last time it fetched up to the current time, minus the timestamp delay.

  • Type: long
  • Default: 0
  • Importance: high

Next Steps

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud ksqlDB, see the Cloud ETL Demo. This example also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.

../_images/topology.png