This guide covers the process of setting up a primary-replica replication environment in MariaDB. Replication allows data from one MariaDB instance (the primary) to be replicated to one or more MariaDB instances (the replicas), ensuring data consistency and redundancy.
Enable Binary Logging:
[mysqld]
log-bin=mysql-bin
server-id=101
systemctl restart mariadb
Create Replication User:
GRANT REPLICATION SLAVE ON *.* TO repl_user@'%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
[mysqld]
log-bin=mysql-bin
server-id=102
read_only=1
report-host=node01.srv.world
systemctl restart mariadb
mariabackup to create a backup of the primary host's data:mariabackup --backup --target-dir /home/mariadb_backup -u root
rsync or scp.Prepare and Restore Backup:
systemctl stop mariadb
rm -rf /var/lib/mysql/*
mariabackup --prepare --target-dir /root/mariadb_backup
mariabackup --copy-back --target-dir /root/mariadb_backup
chown -R mysql. /var/lib/mysql
systemctl start mariadb
Configure Replication:
CHANGE MASTER TO
master_host='primary_host_ip',
master_user='repl_user',
master_password='password',
master_log_file='mysql-bin.000001',
master_log_pos=642;
START SLAVE;
Verify Replication Status:
SHOW SLAVE STATUS\G