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.
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.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.