Skip to main content

mysql_cdc

Streams changes from a MySQL database using its binary log to capture data updates.

The mysql_cdc input captures row-level changes from MySQL and MariaDB databases by reading the binary log (binlog). You can specify which tables to watch and optionally take a consistent snapshot of existing rows before streaming ongoing changes. Progress is stored in a cache resource so the input can resume from its last position after a restart.

# Config fields, showing default values
input:
label: ""
mysql_cdc:
flavor: mysql
dsn: "" # No default (required)
tables: [] # No default (required)
checkpoint_cache: "" # No default (required)
checkpoint_key: mysql_binlog_position
checkpoint_limit: 1024
snapshot_max_batch_size: 1000
stream_snapshot: false # No default (required)
max_parallel_snapshot_tables: 1
max_reconnect_attempts: 10
auto_replay_nacks: true
aws:
enabled: false
region: ""
endpoint: ""
id: ""
secret: ""
token: ""
role: ""
role_external_id: ""
roles:
- role: ""
role_external_id: ""
tls:
skip_cert_verify: false
enable_renegotiation: false
root_cas: ""
root_cas_file: ""
client_certs:
- cert: ""
cert_file: ""
key: ""
key_file: ""
password: ""
batching:
count: 0
byte_size: 0
period: ""
check: ""
processors: []

Examples

Take a consistent snapshot of the orders and customers tables before streaming subsequent changes, storing the binlog position in a cache resource.

input:
mysql_cdc:
dsn: user:password@tcp(localhost:3306)/mydb
tables:
- orders
- customers
checkpoint_cache: mysql_checkpoint
stream_snapshot: true

Fields

flavor

The database flavor to connect to. Supported values are mysql and mariadb.

Type: string
Default: "mysql"

dsn

The Data Source Name for the MySQL connection, in the format [username[:password]@][protocol[(address)]]/dbname. For example, user:password@tcp(localhost:3306)/database.

Type: string

tables

A list of tables to watch for changes and stream data from.

Type: array

checkpoint_cache

The name of a cache resource used to store the current binary log position. This allows the input to resume from where it left off after a restart.

Type: string

checkpoint_key

The key to use when storing the binary log position within the checkpoint cache.

Type: string
Default: "mysql_binlog_position"

checkpoint_limit

The maximum number of messages that can be processed in parallel at a given time before the input waits for acknowledgements.

Type: int
Default: 1024

snapshot_max_batch_size

The maximum number of rows to fetch in a single batch when reading a table snapshot.

Type: int
Default: 1000

stream_snapshot

Whether to take an initial consistent snapshot of the configured tables before streaming changes from the binary log. When enabled, existing rows are emitted before change events.

Type: bool

max_parallel_snapshot_tables

The maximum number of tables to snapshot in parallel when stream_snapshot is enabled.

Type: int
Default: 1

max_reconnect_attempts

The maximum number of reconnection attempts to make after a connection failure before the input reports an error.

Type: int
Default: 10

auto_replay_nacks

Whether messages that are rejected (nacked) at the output level should be automatically replayed indefinitely, eventually resulting in back pressure if the cause of the rejections is persistent. If set to false these messages will instead be deleted. Disabling auto replays can greatly improve memory efficiency of high throughput streams as the original shape of the data can be discarded immediately upon consumption and mutation.

Type: bool
Default: true

aws

Optional configuration for connecting to a MySQL instance hosted on AWS using IAM authentication.

Type: object

aws.enabled

Whether to use AWS IAM authentication when connecting to the database.

Type: bool
Default: false

aws.region

The AWS region to target.

Type: string
Default: ""

aws.endpoint

Allows you to specify a custom endpoint for the AWS API.

Type: string
Default: ""

aws.id

The ID of credentials to use.

Type: string
Default: ""

aws.secret

The secret for the credentials being used. :::warning Secret This field contains sensitive information that usually shouldn't be added to a config directly, read our secrets page for more info. :::

Type: string
Default: ""

aws.token

The token for the credentials being used, required when using short term credentials.

Type: string
Default: ""

aws.role

A role ARN to assume.

Type: string
Default: ""

aws.role_external_id

An external ID to provide when assuming a role.

Type: string
Default: ""

aws.roles

An ordered list of roles to assume when authenticating, allowing role chaining.

Type: array
Default: []

aws.roles.role

A role ARN to assume.

Type: string
Default: ""

aws.roles.role_external_id

An external ID to provide when assuming a role.

Type: string
Default: ""

tls

Custom TLS settings can be used to override system defaults.

Type: object

tls.skip_cert_verify

Whether to skip server side certificate verification.

Type: bool
Default: false

tls.enable_renegotiation

Whether to allow the remote server to repeatedly request renegotiation. Enable this option if you're seeing the error message local error: tls: no renegotiation.

Type: bool
Default: false

tls.root_cas

An optional root certificate authority to use. This is a string, representing a certificate chain from the parent trusted root certificate, to possible intermediate signing certificates, to the host certificate. :::warning Secret This field contains sensitive information that usually shouldn't be added to a config directly, read our secrets page for more info. :::

Type: string
Default: ""

tls.root_cas_file

An optional path of a root certificate authority file to use. This is a file, often with a .pem extension, containing a certificate chain from the parent trusted root certificate, to possible intermediate signing certificates, to the host certificate.

Type: string
Default: ""

tls.client_certs

A list of client certificates to use. For each certificate either the fields cert and key, or cert_file and key_file should be specified, but not both.

Type: array
Default: []

tls.client_certs.cert

A plain text certificate to use.

Type: string
Default: ""

tls.client_certs.cert_file

The path of a certificate to use.

Type: string
Default: ""

tls.client_certs.key

A plain text certificate key to use. :::warning Secret This field contains sensitive information that usually shouldn't be added to a config directly, read our secrets page for more info. :::

Type: string
Default: ""

tls.client_certs.key_file

The path of a certificate key to use.

Type: string
Default: ""

tls.client_certs.password

A plain text password for when the private key is password encrypted in PKCS#1 or PKCS#8 format. The obsolete pbeWithMD5AndDES-CBC algorithm is not supported for the PKCS#8 format. Warning: Since it does not authenticate the ciphertext, it is vulnerable to padding oracle attacks that can let an attacker recover the plain text private key. :::warning Secret This field contains sensitive information that usually shouldn't be added to a config directly, read our secrets page for more info. :::

Type: string
Default: ""

batching

Allows you to configure a batching policy.

Type: object

batching.count

A number of messages at which the batch should be flushed. If 0 disables count based batching.

Type: int
Default: 0

batching.byte_size

An amount of bytes at which the batch should be flushed. If 0 disables size based batching.

Type: int
Default: 0

batching.period

A period in which an incomplete batch should be flushed regardless of its size.

Type: string
Default: ""

batching.check

A Bloblang query that should return a boolean value indicating whether a message should end a batch.

Type: string
Default: ""

batching.processors

A list of processors to apply to a batch as it is flushed. This allows you to aggregate and archive the batch however you see fit. Please note that all resulting messages are flushed as a single batch, therefore splitting the batch into smaller batches using these processors is a no-op.

Type: array
Default: []