# MySQL CDC — Quickstart & Runbook

Page title: MySQL CDC Quickstart

> MySQL CDC quickstart: prerequisites, connector config, verification, acceptance tests, and rollback.

Canonical page: <https://sandgraal.github.io/letstalkcdc/quickstarts/quickstart-mysql/>

Configure binlog safely, register a connector, verify changes, and roll back cleanly.

## Prerequisites (DB)

- **binlog_format=ROW** with **binlog_row_image** FULL or MINIMAL per connector support.
- GTID mode preferred (`gtid_mode=ON`).
- Binlog retention window ≥ snapshot + catch-up time.
- Stable primary keys (or sink logic that can reconcile keyless tables).

- `binlog_format=ROW` captures per-row changes for high-fidelity CDC. `binlog_row_image` controls how much data is logged, and `gtid_mode=ON` simplifies failover by uniquely identifying each transaction across replicas.

```
SHOW VARIABLES LIKE 'binlog_format';
SHOW VARIABLES LIKE 'binlog_row_image';
SHOW VARIABLES LIKE 'gtid_mode';
SHOW MASTER STATUS;
SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';
```

## DB Setup (copy/paste)

```
# my.cnf (server)
binlog_format = ROW
binlog_row_image = FULL
server_id = 1
gtid_mode = ON
enforce_gtid_consistency = ON

# grant minimal privileges to CDC user
GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.*
  TO 'cdc'@'%' IDENTIFIED BY 'cdc';
```

## Connector Config (example)

```
{
  "name": "mysql-cdc",
  "config": {
    "connector.class": "io.debezium.connector.mysql.MySqlConnector",
    "database.hostname": "mysql",
    "database.port": "3306",
    "database.user": "cdc",
    "database.password": "cdc",
    "database.server.id": "5400",
    "topic.prefix": "server1",
    "database.include.list": "app",
    "table.include.list": "app.customer",
    "tombstones.on.delete": "false",
    "include.schema.changes": "false",
    "snapshot.mode": "initial",
    "errors.tolerance": "all",
    "errors.deadletterqueue.topic.name": "dlq.mysql"
  }
}
```

## Verify

```
-- generate a change
UPDATE app.customer SET email = CONCAT(email, '.x')
WHERE id = (SELECT id FROM app.customer LIMIT 1);

-- confirm binlog advancing
SHOW MASTER STATUS;
-- topic should receive a record for app.customer
```

```
kafka-console-consumer --bootstrap-server localhost:9092 \
  --topic server1.app.customer --from-beginning --max-messages 5
```

## Acceptance (target/sink)

- No duplicate PKs after connector restart.
- Latest-wins per key by log position (binlog file + position), not a timestamp.

```
SELECT COUNT(*) AS rows, COUNT(DISTINCT id) AS distinct_keys
FROM target_customers;
```

## Safe Rollback

Stop the connector; keep binlogs until you are sure downstream systems are consistent. If you must prune logs, confirm all consumers are caught up first.

MySQL purges binlogs on a timer, not when a connector has read them, and 8.4 removed `SHOW MASTER STATUS` (use `SHOW BINARY LOG STATUS`). See [SQL Server & MySQL CDC specifics](https://sandgraal.github.io/letstalkcdc/sql-server-mysql-cdc/) for retention, the purge error and recovery.

## Next steps

- Understand the initial load behind `snapshot.mode=initial` in [Snapshotting (Initial Load)](https://sandgraal.github.io/letstalkcdc/snapshotting/).
- Route and fix poison messages with the [DLQ Triage Assistant](https://sandgraal.github.io/letstalkcdc/dlq-triage/), and keep the [first-15-minutes playbook](https://sandgraal.github.io/letstalkcdc/troubleshooting/) handy.
- Other databases: [Postgres quickstart](https://sandgraal.github.io/letstalkcdc/quickstarts/quickstart-postgres/), [SQL Server quickstart](https://sandgraal.github.io/letstalkcdc/quickstarts/quickstart-mssql/), [Oracle quickstart](https://sandgraal.github.io/letstalkcdc/quickstarts/quickstart-oracle/).

---

CDC: The Missing Manual by Christopher Ennis (Let's Talk CDC), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Attribution is required.
