MySQL Data Replication in Ubuntu 18.04..4 LTS

For this configuration, we have setup below mentioned nodes:
Master Node IP : 192.168.1.101
Slave Node IP         : 192.168.1.102

[ Step:01 ]

Install MySQL on the Master server:

#sudo apt-get update
#sudo apt-get install mysql-server

Install MySQL on the Slave server:

#sudo apt-get update
#sudo apt-get install mysql-server


[ Step:02 ]

ON MASTER NODE

#vi sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address            = 192.168.1.101
server-id              = 1
log_bin                = /var/log/mysql/mysql-bin.log

#sudo systemctl restart mysql

#sudo mysql
CREATE USER 'replica'@'192.168.1.102' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'192.168.1.102';

SHOW MASTER STATUS\G

mysql> SHOW MASTER STATUS\G
*************************** 1. row ***************************
             File: mysql-bin.000001
         Position: 887
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)

mysql> CREATE DATABASE replicatest;
Query OK, 1 row affected (0.01 sec)



[ Step:03 ]

ON SLAVE NODE

#vi sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address            = 192.168.1.102
server-id              = 2
log_bin                = /var/log/mysql/mysql-bin.log

#sudo systemctl restart mysql

#sudo mysql

STOP SLAVE;

CHANGE MASTER TO
MASTER_HOST='192.168.1.101',
MASTER_USER='replica',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=887;

START SLAVE;


Test the Configuration



[ Step:04 ]

ON MASTER NODE

#sudo mysql

CREATE DATABASE replicatest;

ON SLAVE NODE

#sudo mysql

SHOW DATABASES;

mysql> show databases;
+--------------------------+
| Database                     |
+--------------------------+
| information_schema   |
| bolcorp2                      |
| mysql                           |
| performance_schema  |
| replicatest                    |
| replicatest2                  |
| sys                               |
+--------------------------+
7 rows in set (0.00 sec)




Reference Links:
1. https://linuxize.com/post/how-to-configure-mysql-master-slave-replication-on-ubuntu-18-04/
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Comments

Popular posts from this blog

Cambium cnPilot E400/E410/E500 Configuration Tutorial

Disabling Zimbra's AntiSpam, Amavis and AntiVirus filtering

Error "Unable to retrive Zimbra GPG key for package validation"