0% found this document useful (0 votes)
79 views7 pages

Configuring Master-Master Replication On Mariadb: 1. Mariadb: Configuration of The First Master Server (Master-1)

This document discusses configuring Master-Master replication between two MariaDB database servers. It involves setting up binary logging and replication users on each server, then initiating replication by specifying the replication configuration and starting the slave processes on each server. The replication status is checked and testing is done by creating databases and tables on one server and verifying they are replicated to the other server.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views7 pages

Configuring Master-Master Replication On Mariadb: 1. Mariadb: Configuration of The First Master Server (Master-1)

This document discusses configuring Master-Master replication between two MariaDB database servers. It involves setting up binary logging and replication users on each server, then initiating replication by specifying the replication configuration and starting the slave processes on each server. The replication status is checked and testing is done by creating databases and tables on one server and verifying they are replicated to the other server.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Configuring Master-Master Replication on MariaDB

In a Master-Master replication scheme, any of the MariaDB database servers may be used both to
write or read data. Replication is based on a special binlog file, a Master server saves all operations
with the database to. A Slave server connects to the Master and applies the commands to its
databases.

1. MariaDB: Configuration of the First Master Server (Master-1)


Add the following lines to my.cnf file on your first MariaDB server:
#replication

server-id = 1

report_host = master

log_bin = /var/lib/mysql/mariadb-bin

log_bin_index = /var/lib/mysql/mariadb-bin.index

relay_log = /var/lib/mysql/relay-bin

relay_log_index = /var/lib/mysql/relay-bin.index

service mariadb restart


Create a user to configure replication:
mysql
create user 'test_master'@'%' identified by 'test_master';
grant replication slave on *.* to 'test_master'@'%';
To add a Slave, we need to get bin_log data from the Master-1 server:

MariaDB [(none)]> show master status;


+--------------------+----------+--------------+------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+--------------------+----------+--------------+------------------+

| mariadb-bin.000002 | 664 | | |

+--------------------+----------+--------------+------------------+

1 row in set (0.000 sec)

2. MariaDB: Configuration of the Second Master Server (Master-2)


Connect to the second MariaDB server, open the my.cnf file and add the following configuration to
it:

#replication

server-id = 2

report_host = master2

log_bin = /var/lib/mysql/mariadb-bin

log_bin_index = /var/lib/mysql/mariadb-bin.index

relay_log = /var/lib/mysql/relay-bin

relay_log_index = /var/lib/mysql/relay-bin.index
Create a new user on the second server as well:

create user 'test_master2'@'%' identified by 'test_master2';


grant replication slave on *.* to 'test_master2'@'%';

Get bin_log on Master-2:

MariaDB [(none)]> show master status;


+--------------------+----------+--------------+------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+--------------------+----------+--------------+------------------+

| mariadb-bin.000001 | 667 | | |

+--------------------+----------+--------------+------------------+

1 row in set (0.000 sec)

Let’s configure the connection between MariaDB servers in our software replication cluster:

Stop the slave:

STOP SLAVE;
Add Master-1 to the second server:

CHANGE MASTER TO MASTER_HOST='IP_master1', MASTER_USER='test_master',


MASTER_PASSWORD='test_master', MASTER_LOG_FILE='mariadb-bin.000002',
MASTER_LOG_POS=664;
Start the replication:

START SLAVE;

Connect to Master-1 and follow the same steps, but specify the information about the second server
instead:
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='10.2.10.36', MASTER_USER='test_master2',
MASTER_PASSWORD='test_master2', MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=667;
START SLAVE;
Check the second server status:

show slave status \G

As you can see in the screenshots, there is the connection between two servers, and no errors
occur.

3. How to Check Replication Between MariaDB Servers?


Then to make sure that the replication between two MariaDB servers works in master+master, we
will create a new database on Master-1 and create a table in it.

MariaDB [(none)]> create database master1;


MariaDB [(none)]> use master1;
MariaDB [master1]> CREATE TABLE hello (
-> AuthorID INT NOT NULL AUTO_INCREMENT,
-> AuthorName VARCHAR(100),
-> PRIMARY KEY(AuthorID)
-> );

Make sure that this database has automatically replicated on the second master and contains the
same table:

MariaDB [(none)]> show databases;


+--------------------+

| Database |

+--------------------+

| information_schema |
| master1 |

| mysql |

| performance_schema |

+--------------------+

MariaDB [(none)]> use master1;


MariaDB [master1]> show tables;
+-------------------+

| Tables_in_master1 |

+-------------------+

| hello |

+-------------------+

The database has been created on the second master as well. To check the full cycle, create a table
in the Master1 database on the second Master server and check if it appears on the first server.

MariaDB [master1]> CREATE TABLE hello_master1 (


-> AuthorID INT NOT NULL AUTO_INCREMENT,
-> AuthorName VARCHAR(100),
-> PRIMARY KEY(AuthorID)
-> );
The hello_master1 table has been replicated to the first server:

MariaDB [master1]> show tables;


+-------------------+

| Tables_in_master1 |

+-------------------+

| hello |

| hello_master1 |

+-------------------+

The new table has appeared on Master-1. The replication works.

You might also like