MySQL Replication Setup
MySQL Replication Setup
https://www.linkedin.com/posts/naveen-gomangi-aa85bb184_steps-for-an-installation-of-
mysql-84-activity-7270113700815003649-
z0OG?utm_source=share&utm_medium=member_desktop
wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
mysql_secure_installation
wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
mysql_secure_installation
Each server within a replication topology must be configured with a unique server ID, which you
can specify using the server_id system variable. This server ID is used to identify individual
servers within the replication topology, and must be a positive integer between 1 and (232)−1.
The default server_id value is 1
Binary logging is required on the source because the binary log is the basis for replicating
changes from the source to its replicas. Binary logging is enabled by default (the log_bin system
variable is set to ON). The --log-bin option tells the server what base name to use for binary log
files. It is recommended that you specify this option to give the binary log files a non-default
base name, so that if the host name changes, you can easily continue to use the same binary
log file names
For the greatest possible durability and consistency in a replication setup using InnoDB with
transactions, you should use innodb_flush_log_at_trx_commit=1 and sync_binlog=1 in the
source's my.cnf file.
server-id=1
log-bin=/var/lib/mysql/mysql-bin.log
innodb_flush_log_at_trx_commit=1
sync_binlog=1
save&exit
Each replica must have a unique server ID, as specified by the server_id system variable. If you
are setting up multiple replicas, each one must have a unique server_id value that differs from
that of the source and from any of the other replicas. If the replica's server ID is not already set,
or the current value conflicts with the value that you have chosen for the source or another
replica, you must change it.
The relay log contains a record of events that affect the data or structure of a database.
server-id=2
relay-log = /var/lib/mysql/mysql-relay-bin.log
log_bin = /var/lib/mysql/mysql-bin.log
save&exit
-- Create a database
USE SampleDB;
-- Create tables
INSERT INTO Employees (FirstName, LastName, Department, Salary) VALUES('John', 'Doe', 'HR',
60000.00),('Jane', 'Smith', 'IT', 75000.00),('Michael', 'Brown', 'Finance', 50000.00),('Emily', 'Davis',
'HR', 58000.00),('Robert', 'Johnson', 'IT', 80000.00);
Step10) Obtaining the Replication Source Binary Log Coordinates on the source server:
Flush all tables and block write statements by executing the FLUSH TABLES WITH READ
LOCK statement:
FLUSH TABLES WITH READ LOCK;
Use the SHOW BINARY LOG STATUS statement to determine the current binary log file
name and position:
The File column shows the name of the log file and the Position column shows the position
within the file. In this example, the binary log file is mysql-bin.000004 and the position is 2867.
Record these values. You need them later when you are setting up the replica. They represent
the replication coordinates at which the replica should begin processing new updates from the
source.
Step11) Creating a Source Server Data Snapshot Using mysqldump on the Replica Server:
UNLOCK TABLES;
Step13) Restoring the Source Server Data Snapshot Using mysql on the Replica Server:
START REPLICA;
USE SampleDB;
INSERT INTO Persons (PersonID, LastName, FirstName, Address, City) VALUES(1, 'Smith', 'John',
'123 Elm Street', 'New York'),(2, 'Johnson', 'Mary', '456 Oak Avenue', 'Los Angeles'),(3, 'Brown',
'James', '789 Pine Road', 'Chicago'),(4, 'Taylor', 'Patricia', '101 Maple Lane', 'Houston'),(5,
'Anderson', 'Robert', '202 Birch Blvd', 'Phoenix');
USE SampleDB;
SHOW TABLES;
Enable below parameters to prevent the write operations on the replica server:
If the read_only system variable is enabled, the server permits no client updates except from
users who have the CONNECTION_ADMIN privilege (or the deprecated SUPER privilege). This
variable is disabled by default.
If super_read_only is enabled, the server prohibits client updates, even from users who have
the CONNECTION_ADMIN or SUPER privilege.
SET @@GLOBAL.super_read_only=ON;