filmov
tv
MySQL :How to Configure Mysql master slave replication in MYSQL database

Показать описание
MySQL :How to Configure MySQL Master-Slave Replication on RHEL
*********************************************************************
MySQL replication procedure enabled you to automatically copy data from one MYSQL database server to one or more MYSQL servers.
MySQL supports a number of replication topologies with Master/Slave topology being one of the most well-known topologies in which
one database server acts as the master, while one or more servers act as slaves. By default, the replication is asynchronous where
the master sends events that describe database modifications to its binary log and slaves request the events when they are ready.
This sort of replication topology is good for deploying of read replicas for read scaling, live databases backup
for disaster recovery and for analytics jobs.
MySQL 8.0 supports different methods of replication. The traditional method is based on replicating events from the master's binary log,
and requires the log files and positions in them to be synchronized between master and slave.
Prerequisites
*************
Setup
*******
ROLE HOST OS MYSQL SERVER VERSION
Master 192.168.1.51(linux2) OEL 6.5 8.0.19
Slave 192.168.1.61(linux3) OEL 6.5 8.0.19
vaidate value of
show variables like '%uuid%';
Step 1: Configure the Master Server.
*************************************
-Let's configure the master MySQL server and perform below changes.
-enable MySQL server to listen on the private IP.
-Set a unique server ID.
-Enable the binary logging.
#
bind-address = 192.168.1.51
server-id = 1
log_bin = mysql-bin
-Once done, restart the MySQL service for changes to take effect
# service mysqld restart
-create a new replication user who can login master server from slave server.
mysql -u root -p
SHOW MASTER STATUS\G
*************************** 1. row ***************************
File: mysql-bin.000022
Position: 155
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.01 sec)
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'192.168.1.61';
***************************************************
Like master server perform below changes on slave server.
Set the MySQL server to listen on the private IP
Set a unique server ID
Enable the binary logging
bind-address = 192.168.1.61
server-id = 2
log_bin = mysql-bin
# service mysqld restart
Step 3: Configure the parameters for slave server to connect to the master server.
***********************************************************************************
mysql -uroot -p
STOP SLAVE;
CHANGE MASTER TO
MASTER_HOST='192.168.1.51',
MASTER_USER='replica',
MASTER_LOG_FILE='mysql-bin.000023',
MASTER_LOG_POS=686;
start slave;
show slave status\G;
show variables like '%uuid%';
testing
*******
Create database testreplica;
use testreplica;
CREATE TABLE `departments` (
`dept_no` char(4) NOT NULL,
`dept_name` varchar(40) NOT NULL,
PRIMARY KEY (`dept_no`),
UNIQUE KEY `dept_name` (`dept_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
*********************************************************************
MySQL replication procedure enabled you to automatically copy data from one MYSQL database server to one or more MYSQL servers.
MySQL supports a number of replication topologies with Master/Slave topology being one of the most well-known topologies in which
one database server acts as the master, while one or more servers act as slaves. By default, the replication is asynchronous where
the master sends events that describe database modifications to its binary log and slaves request the events when they are ready.
This sort of replication topology is good for deploying of read replicas for read scaling, live databases backup
for disaster recovery and for analytics jobs.
MySQL 8.0 supports different methods of replication. The traditional method is based on replicating events from the master's binary log,
and requires the log files and positions in them to be synchronized between master and slave.
Prerequisites
*************
Setup
*******
ROLE HOST OS MYSQL SERVER VERSION
Master 192.168.1.51(linux2) OEL 6.5 8.0.19
Slave 192.168.1.61(linux3) OEL 6.5 8.0.19
vaidate value of
show variables like '%uuid%';
Step 1: Configure the Master Server.
*************************************
-Let's configure the master MySQL server and perform below changes.
-enable MySQL server to listen on the private IP.
-Set a unique server ID.
-Enable the binary logging.
#
bind-address = 192.168.1.51
server-id = 1
log_bin = mysql-bin
-Once done, restart the MySQL service for changes to take effect
# service mysqld restart
-create a new replication user who can login master server from slave server.
mysql -u root -p
SHOW MASTER STATUS\G
*************************** 1. row ***************************
File: mysql-bin.000022
Position: 155
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.01 sec)
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'192.168.1.61';
***************************************************
Like master server perform below changes on slave server.
Set the MySQL server to listen on the private IP
Set a unique server ID
Enable the binary logging
bind-address = 192.168.1.61
server-id = 2
log_bin = mysql-bin
# service mysqld restart
Step 3: Configure the parameters for slave server to connect to the master server.
***********************************************************************************
mysql -uroot -p
STOP SLAVE;
CHANGE MASTER TO
MASTER_HOST='192.168.1.51',
MASTER_USER='replica',
MASTER_LOG_FILE='mysql-bin.000023',
MASTER_LOG_POS=686;
start slave;
show slave status\G;
show variables like '%uuid%';
testing
*******
Create database testreplica;
use testreplica;
CREATE TABLE `departments` (
`dept_no` char(4) NOT NULL,
`dept_name` varchar(40) NOT NULL,
PRIMARY KEY (`dept_no`),
UNIQUE KEY `dept_name` (`dept_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Комментарии