$ yum install mariadb-server
$ systemctl restart mariadb
$ systemctl enable mariadb
$ mysql_secure_installation
On /etc/my.cnf, add
server_id=1
log-basename=master
log-bin
$ systemctl restart mariadb
$ mysql -u root -p
MariaDB [(none)]> STOP SLAVE;
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY 'mypassword';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> FLUSH TABLES WITH READ LOCK;
MariaDB [(none)]> SHOW MASTER STATUS;
+--------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000001 | 460 | | |
+--------------------+----------+--------------+------------------+
Keep session on, don’t logout. Open new terminal and dump the db to file:
$ mysqldump --all-databases --user=root --password --master-data > masterdatabase.sql
Back on the previous terminal:
MariaDB [(none)]> UNLOCK TABLES;
Copy the dump file to slave server
$ scp masterdatabase.sql root@slave.server.com:/root/
$ yum install mariadb-server
$ systemctl restart mariadb
$ systemctl enable mariadb
$ mysql_secure_installation
On /etc/my.cnf, put server_id=2. Then import the copy from the master database.
$ mysql -u root -p < masterdatabase.sql
$ systemctl restart mariadb
$ mysql -u root -p
MariaDB [(none)]> STOP SLAVE;
MariaDB [(none)]>
CHANGE MASTER TO
MASTER_HOST='master.server.com',
MASTER_USER='slave',
MASTER_PASSWORD='mypassword',
MASTER_PORT=3306,
MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=460,
MASTER_CONNECT_RETRY=10;
MariaDB [(none)]> SLAVE START;
MariaDB [(none)]> SHOW SLAVE STATUS\G;