In this document, we will discuss how to enable replication on an existing MariaDB database.

<aside> 💡 Notes → All of the shell commands will be performed inside of the SFTP container. → Whenever you see the server-id, this needs to be a unique number for each server. → When you see -pPW in the mysql commands, the lack of a space is intentional!

</aside>

Prepare Primary Database

Enable Replication

Edit the running service and add the following commands to the Command Override section.

--log-bin --binlog-format=mixed --server-id=1001 --log-basename=primary1 --expire-logs-days=2

Rebuild the primary database container.

Create the replication user

From the sftp container, gain access to the mysql console with: mysql -u root -h IP-Of-Primary -p

CREATE USER 'repluser'@'%' IDENTIFIED BY 'bigs3cret';
GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'%';

Dump database on primary

Enter a SQL shell once again, and run:

FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;
SHOW MASTER STATUS;