feat: add mariadb and mysql differences

This commit is contained in:
Simon Cornet 2025-11-21 12:00:55 +01:00
commit dee1f340b8

View file

@ -1,6 +1,6 @@
# MySQL / MariaDB replication # MySQL / MariaDB replication
This is tested on MariaDB 11. This is tested on MariaDB 11 and MySQL 8.0.
## Prepare source server/database ## Prepare source server/database
@ -10,6 +10,8 @@ This is tested on MariaDB 11.
/etc/mysql/conf.d/mysqld.cnf /etc/mysql/conf.d/mysqld.cnf
``` ```
MariaDB:
```shell ```shell
[mysqld] [mysqld]
server-id = 1 server-id = 1
@ -21,7 +23,22 @@ gtid_strict_mode = 1
log_slave_updates = 1 log_slave_updates = 1
``` ```
MySQL:
```shell
[mysqld]
server-id = 1
log_bin = /var/lib/mysql/mysql-bin.log
binlog_format = ROW
binlog-expire-logs-seconds = 172800
max_binlog_size = 100M
gtid_mode = ON
enforce_gtid_consistency = ON
log_slave_updates = 1
```
Restart mariadb: `systemctl restart mariadb` Restart mariadb: `systemctl restart mariadb`
Restart mysql: `systemctl restart mysql`
### Create replication user ### Create replication user
@ -38,15 +55,16 @@ FLUSH PRIVILEGES;
### Create database dump ### Create database dump
MariaDB:
```shell ```shell
mariadb-dump -u root -psupersecuresource --single-transaction --gtid --master-data=1 --databases databeast > /tmp/databeast.sql mariadb-dump -u root -psupersecuresource --single-transaction --gtid --master-data=1 --databases databeast > /tmp/databeast.sql
``` ```
Or feel lucky with pipes... Execute this from the replica host. MySQL:
```shell ```shell
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS databeast;" mysqldump -u root -psupersecuresource --single-transaction --set-gtid-purged=ON --source-data=1 --databases databeast > /tmp/databeast.sql
mariadb-dump -h source.example.com -u root -p --single-transaction --databases databeast | pv | mysql -u root -p
``` ```
## Configure replicate ## Configure replicate
@ -57,6 +75,8 @@ mariadb-dump -h source.example.com -u root -p --single-transaction --databases d
/etc/mysql/conf.d/mysqld.cnf /etc/mysql/conf.d/mysqld.cnf
``` ```
MariaDB:
```shell ```shell
[mysqld] [mysqld]
server-id = 2 server-id = 2
@ -69,7 +89,25 @@ gtid_strict_mode = 1
log_slave_updates = 1 log_slave_updates = 1
``` ```
MySQL:
```shell
[mysqld]
server-id = 2
relay_log = /var/lib/mysql/mysql-relay-bin
read_only = 1
replicate-do-db = databeast
log_bin = /var/lib/mysql/mysql-bin.log
binlog_format = ROW
binlog-expire-logs-seconds = 172800
max_binlog_size = 100M
gtid_mode = ON
enforce_gtid_consistency = ON
log_slave_updates = 1
```
Restart mariadb: `systemctl restart mariadb` Restart mariadb: `systemctl restart mariadb`
Restart mysql: `systemctl restart mysql`
### Copy database dump ### Copy database dump
@ -86,23 +124,31 @@ mysql -u root -p < /tmp/databeast.sql
### Import in one go ### Import in one go
If you feel lucky with pipes...
MariaDB:
```shell ```shell
mariadb-dump -h source.example.com \ mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS databeast;"
-u replicator \ mariadb-dump -h source.example.com -u root -p --single-transaction --databases databeast | mysql -u root -psupersecure
-psupersecure \
--single-transaction \
--gtid \
--master-data=1
--databases databeast | \
mysql -u replicator -psupersecure databeast
``` ```
MySQL:
```shell
mysql -u root -psupersecuresource -e "CREATE DATABASE IF NOT EXISTS databeast;"
mysqldump -u root -h source.example.com -psupersecuresource --single-transaction --set-gtid-purged=ON --source-data=1 --databases pms | mysql -u root -psupersecure
```
### Activate replication ### Activate replication
```shell ```shell
mysql -u root -p mysql -u root -p
``` ```
MariaDB:
```shell ```shell
STOP SLAVE; STOP SLAVE;
RESET SLAVE; RESET SLAVE;
@ -114,6 +160,18 @@ CHANGE MASTER TO
START SLAVE; START SLAVE;
``` ```
MySQL:
```shell
STOP REPLICA;
RESET REPLICA;
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='source.example.com',
SOURCE_USER='replicator',
SOURCE_PASSWORD='supersecure',
SOURCE_AUTO_POSITION=1;
START REPLICA;
```
## Monitor replication ## Monitor replication
```shell ```shell