Databases 4 min read

MySQL 8.0 Master‑Slave Replication Configuration Guide

This tutorial walks through installing MySQL 8.0 on two servers, enabling binary logging, creating a replication user, configuring master and slave settings, handling common errors, and verifying that master‑slave synchronization works correctly.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
MySQL 8.0 Master‑Slave Replication Configuration Guide

This article demonstrates how to set up MySQL 8.0 master‑slave replication on two servers (192.168.210.85 as master and 192.168.210.177 as slave).

1. Enable binary logging on the master

mysql> SET GLOBAL log_bin = ON;

2. Create a replication user on the master and grant privileges

mysql> CREATE USER 'repl'@'192.168.210.177' IDENTIFIED BY '123456';

mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.210.177';

mysql> FLUSH PRIVILEGES;

3. Check master status

mysql> SHOW MASTER STATUS;

4. Configure the slave

mysql> CHANGE MASTER TO MASTER_HOST='192.168.210.85', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=586;

mysql> START SLAVE;

If the slave reports an error, stop it first:

mysql> STOP SLAVE;

Then repeat the CHANGE MASTER TO command with the correct parameters and start the slave again.

Check slave status:

mysql> SHOW SLAVE STATUS\G;

5. Verify replication

Create a test database on the master:

mysql> CREATE DATABASE mzl;

Then check the slave to confirm the database appears, indicating successful synchronization.

When the verification image shows the database on the slave, the master‑slave replication is confirmed to be working.

Please scan the QR code to follow us.

DatabaseMySQLMaster‑SlaveReplicationMySQL8
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.