CDC Sink for MySQL: Overview
-
CDC Sink supports MySQL and MariaDB as source databases using binary log (binlog) replication.
-
MySQL and MariaDB record row-level changes in the binlog.
The CDC Sink task reads the binlog stream continuously and processes INSERT, UPDATE, and DELETE events according to the task configuration. -
In this article:
Connection string
Use a SqlConnectionString with FactoryName set to "MySqlConnector.MySqlConnectorFactory".
The legacy "MySql.Data.MySqlClient" factory name is still accepted,
but the server automatically replaces it with "MySqlConnector.MySqlConnectorFactory" and raises a deprecation notification.
- Sync
- Async
store.Maintenance.Send(new PutConnectionStringOperation<SqlConnectionString>(
new SqlConnectionString
{
Name = "MySqlConnection",
FactoryName = "MySqlConnector.MySqlConnectorFactory",
ConnectionString =
"Server=myserver;Port=3306;" +
"Database=mydb;User=ravendb_cdc;Password=..."
}));
await store.Maintenance.SendAsync(new PutConnectionStringOperation<SqlConnectionString>(
new SqlConnectionString
{
Name = "MySqlConnection",
FactoryName = "MySqlConnector.MySqlConnectorFactory",
ConnectionString =
"Server=myserver;Port=3306;" +
"Database=mydb;User=ravendb_cdc;Password=..."
}));
Prerequisites
MySQL/MariaDB must have binary logging enabled with row-based format:
- my.cnf
# my.cnf / my.ini
[mysqld]
log-bin = mysql-bin
binlog_format = ROW
binlog_row_image = FULL
server-id = 1
# MySQL only: CDC Sink requires GTID.
# This is not needed for MariaDB.
enforce_gtid_consistency = ON
gtid_mode = ON
On MySQL, CDC Sink requires gtid_mode = ON.
If GTID is not already enabled, configure it before starting the CDC Sink task.
For an existing MySQL server, follow MySQL's GTID enablement procedure.
MariaDB always has GTID support enabled, so no gtid_mode setting is needed there.
The MySQL/MariaDB user in the CDC Sink connection string needs the following privileges:
- SQL
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'ravendb_cdc'@'%';
GRANT SELECT ON mydb.* TO 'ravendb_cdc'@'%';
REPLICATION SLAVE- required to read the binlog streamREPLICATION CLIENT- required to query binlog statusSELECT- required for the initial full-table load
Streaming behavior
After the initial load, MySQL/MariaDB CDC Sink reads row-based binlog events continuously.
It does not poll the source database for changes, so the CdcSink.SqlServer.PollIntervalInSec server configuration setting
applies only to SQL Server CDC Sink tasks and has no effect on MySQL/MariaDB.
Task configuration
Most CDC Sink task configuration is shared across supported source database engines.
See Configuration Reference
for full details, including table mappings, delete behavior, and patches.
When SourceTableSchema is omitted, MySQL/MariaDB uses the database name from the connection string as the default schema.