# Enable binary log for MySQL or MariaDB

Configure MySQL binary logging to enable incremental backups and point-in-time recovery.

Binary logs record every change made to your database, allowing SimpleBackups to capture only what changed since the last full backup. Enabling binary logging requires editing the MySQL configuration file, granting your backup user replication privileges, and restarting MySQL.

## Step 1 — Update the MySQL configuration

Edit your MySQL config file, typically at `/etc/my.cnf` or `/etc/mysql/my.cnf`. Add the following under the `[mysqld]` section:

```plain
[mysqld]
server_id           = 1
log_bin             = /var/log/mysql/mysql-bin.log
max_binlog_size     = 100M
binlog_format       = mixed
```

For MySQL 8+, also add:

```plain
binlog_expire_logs_seconds = 864000
```

For MySQL 5, add:

```plain
expire_logs_days = 10
```

## Step 2 — Grant replication privileges

Grant your backup user the `REPLICATION SLAVE` privilege from the MySQL shell:

```sql
GRANT REPLICATION SLAVE ON *.* TO 'mybackupsuser'@'%';
```

Replace `mybackupsuser` with the user SimpleBackups uses to connect to your database.

## Step 3 — Restart MySQL

```bash
sudo service mysql restart
```

After the restart, SimpleBackups will detect the binary log configuration and include incremental log files in your backups.
