MySQL primary-replica replication allows one database server (the primary) to stream changes to one or more replica servers in near real-time, providing read scalability and a warm standby for disaster recovery. On RHEL 8, the setup involves editing MySQL configuration files on both servers, creating a dedicated replication user, and issuing a handful of SQL commands to wire the replica to the primary. This tutorial uses two RHEL 8 servers running MySQL 8.0 and configures row-based binary log replication, which is the recommended format for modern workloads.
Prerequisites
- Two RHEL 8 servers — primary (e.g., 192.168.1.10) and replica (e.g., 192.168.1.11)
- MySQL 8.0 installed and running on both servers
- The MySQL root password set on both servers
- Both servers able to communicate on port 3306 (firewalld configured)
- A sudo-capable user on each server
Step 1 — Configure the Primary Server
Open the MySQL configuration file on the primary server and add the directives that enable binary logging and assign a unique server ID.
sudo nano /etc/my.cnf
Add or update the following lines under the [mysqld] section:
[mysqld]
server-id = 1
log_bin = /var/lib/mysql/mysql-bin
binlog_format = ROW
binlog_row_image = FULL
expire_logs_days = 7
bind-address = 0.0.0.0
Save the file and restart MySQL to apply the settings:
sudo systemctl restart mysqld
Step 2 — Open Port 3306 on the Primary
Allow the replica to connect to MySQL on the primary server through firewalld. If you want tighter control, use a rich rule scoped to the replica’s IP instead of opening the service site-wide.
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.11" port protocol="tcp" port="3306" accept'
sudo firewall-cmd --reload
Step 3 — Create the Replication User on the Primary
Log in to MySQL on the primary server and create a dedicated account that the replica will use to connect. Grant only the REPLICATION SLAVE privilege so the account cannot be used for anything else.
mysql -u root -p
CREATE USER 'repl'@'192.168.1.11' IDENTIFIED WITH mysql_native_password BY 'StrongRepl@Pass1';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.11';
FLUSH PRIVILEGES;
Now record the current binary log file and position. Keep this output — you will need it when configuring the replica.
SHOW MASTER STATUS;
Sample output:
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 769 | | |
+------------------+----------+--------------+------------------+
Step 4 — Configure the Replica Server
On the replica server, open /etc/my.cnf and assign a unique server ID. The replica does not need binary logging enabled unless it will itself act as a primary in a chain.
sudo nano /etc/my.cnf
[mysqld]
server-id = 2
relay-log = /var/lib/mysql/mysql-relay-bin
log_slave_updates = ON
read_only = ON
sudo systemctl restart mysqld
Step 5 — Point the Replica at the Primary and Start Replication
Log in to MySQL on the replica and run CHANGE MASTER TO, substituting the file and position values from Step 3.
mysql -u root -p
CHANGE MASTER TO
MASTER_HOST='192.168.1.10',
MASTER_USER='repl',
MASTER_PASSWORD='StrongRepl@Pass1',
MASTER_LOG_FILE='mysql-bin.000003',
MASTER_LOG_POS=769;
START SLAVE;
Step 6 — Verify Replication Status
Check the replica status to confirm both I/O and SQL threads are running and that there are no errors.
SHOW SLAVE STATUSG
Look for the following lines in the output:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
If either thread shows No, inspect the Last_IO_Error and Last_SQL_Error fields in the same output for diagnostics.
Conclusion
You have configured MySQL primary-replica replication on RHEL 8 using row-based binary logging. The primary streams every data change to the replica, which replays them in order. You can now direct read-heavy application queries to the replica to reduce load on the primary, or promote the replica to primary in the event of a failure. Regularly monitor Seconds_Behind_Master and the MySQL error log to catch replication lag or errors early.
Next steps: How to Configure MySQL Group Replication on RHEL 8, How to Back Up and Restore MySQL Databases on RHEL 8, and How to Monitor MySQL Performance with the Performance Schema on RHEL 8.