# CDC setup in Mysql

## MySQL CDC setup on Linux

* Create a user for sprinkle, choosing your own password

```
CREATE USER sprinkle@'%' IDENTIFIED WITH mysql_native_password BY 'password';

GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO sprinkle@'%';
```

* Check if following lines are there in the mysql configuration file (my.cnf), otherwise add them:

```
[mysqld]

binlog-format=ROW

log-bin=mysql-binlog

server-id=67835629

expire-logs-days=7

log-slave-updates=1
```

* binlog-format must be ROW
* No need to change log-bin entry if it is already there
* No need to change if Server-id is already there. Otherwise choose any value between 1000 and 4294967295
* expire-logs we recommend should be 7 days.
* Restart Mysql server for new config to take effect.
* (Optional) After restart you can check the variables using : show variables like '%binlog\_format%';

## AWS MySQL CDC setup

Below are the configuration steps to enable binlog in AWS mysql.

### 1. Create parameter group

&#x20;           If you have a default parameter group, you must create a new parameter group. Alternatively, you can copy your existing cluster parameter group.

&#x20;             **Check the parameter group for mysql instance under configuration tab**

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04ee717fbef7098bbc7_cdc-mysql1.png)

&#x20;          Select parameter group family should be equal to instance of mysql. Give name and description.

&#x20;          Now after creating a new parameter group change two parameters.

* Binlog\_format to ROW
* Binlog\_row\_image to full

### 2. Use the main instance or create new Read replica for mysql instance Creating a new read replica instance.

&#x20;           A. Select the instance and go to Actions.Now select create read replica.

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04eaaa19a8293d0bf86_cdc-mysql2.png)

&#x20;            B. Give the name for your replica and Replica source should be mysql.

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04faaa19a744dd0bf87_cdc-mysql3.png)

&#x20;             C. Public accessibility should be yes.

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04f8d675056c5f25860_cdc-mysql4.png)

&#x20;             D. Backup retention period should be greater than 1.

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04ff672870966223cb5_cdc-mysql5.png)

&#x20;             E. DB parameter group should be the newly created parameter group.

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04f5deb9f110f996ff3_cdc-mysql6.png)

### 3. Modify and use the instance

&#x20;           After modifying the instance reboot DB.

![](https://uploads-ssl.webflow.com/605c9e03d6553a5d82976ce2/6087a04f79ff713c9919d3d3_cdc-mysql7.png)

### 4. Setup binlog retention

&#x20;           To set a longer binlog retention period, run the following command on the connected database.

```
CALL mysql.rds_set_configuration('binlog retention hours', 168);
```

### 5. Create read user

```
CREATE USER sprinkle_user@'%' IDENTIFIED WITH mysql_native_password BY 'password';

GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO sprinkle_user@'%';
```
