Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up MySQL 8.0 Master-Slave Replication (Single Master-Single Slave) on openEuler 22.03

Tech May 17 2
Role Operating System IP Address MySQL Version
Master Node openEuler 22.03 LTS-SP2 192.168.48.131 8.0.37 for Linux on x86_64 (Source distribution)
Slave Node openEuler 22.03 LTS-SP2 192.168.48.132 8.0.37 for Linux on x86_64 (Source distribution)
# Install MySQL server
yum install -y mysql-server
# Allow MySQL port 3306 in firewall (skip if firewall is inactive)
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports | grep 3306
# Disable SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
reboot
# Start MySQL service
systemctl start mysqld
# Verify MySQL startup
ps -ef | grep mysql
# Enable MySQL auto-start on boot
systemctl enable mysqld
# Log into MySQL
mysql -uroot -p

First login to this MySQL version has an empty password; press Enter directly.


Master Node Configuration

1.1 Modify MySQL Configuration File

cat >> /etc/my.cnf <<EOF
server-id=1
read-only=0
binlog_format=MIXED
log-slave-updates=true
log-bin=mysql-repl-log
EOF

1.2 Restart MySQL Service

systemctl restart mysqld

1.3 Create Replication User

CREATE USER 'luna'@'192.168.48.132' IDENTIFIED WITH mysql_native_password BY 'Luna@456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'luna'@'192.168.48.132';
FLUSH PRIVILEGES;

1.4 Check Binary Log Coordinates

SHOW MASTER STATUS\G;
  • Current binary log filename: mysql-repl-log.000001
  • Current offset: 2405

Slave Node Configuration

2.1 Modify MySQL Configuration File

cat >> /etc/my.cnf <<EOF
server-id=2
EOF

2.2 Restart MySQL Service

systemctl restart mysqld

2.3 Configure Master-Slave Connection

CHANGE MASTER TO 
  MASTER_HOST='192.168.48.131',
  MASTER_USER='luna',
  MASTER_PASSWORD='Luna@456',
  MASTER_LOG_FILE='mysql-repl-log.000001',
  MASTER_LOG_POS=2405;

2.4 Start Replication

START SLAVE;
SHOW SLAVE STATUS\G;

Both Slave_IO_Running and Slave_SQL_Running should show Yes.


Validate Replication

3.1 Create Test Data on Master

CREATE DATABASE dev_test;
USE dev_test;
CREATE TABLE employee (
  emp_id INT,
  emp_name VARCHAR(50)
) CHARSET=utf8;
INSERT INTO employee VALUES
(101, 'Alice'),
(102, 'Bob'),
(103, 'Charlie');

3.2 Verify Data on Slave

SHOW DATABASES;
SELECT * FROM dev_test.employee;

The dev_test database and employee table with inserted records should appear on the slave.


Troubleshooting

Slave_IO_Running: No

Common Causes & Fixes

  1. Incorrect binary log coordinates: Re-check coordinates from SHOW MASTER STATUS on the master and reconfigure the slave.
  2. Failed remote connection: Verify firewall, SELinux, and network connectivity.
  3. Duplicate server UUID/MAC address: Generated if nodes are cloned; modify /var/lib/mysql/auto.cnf to change UUID.

Slave_IO_Running: Connecting

Cause: The replication user was created using the default caching_sha2_password plugin, which requires a secure TLS connectino for remote access.

Fix:

ALTER USER 'luna'@'192.168.48.132' IDENTIFIED WITH mysql_native_password BY 'Luna@456';

Authenticasion Plugin Difference

CREATE USER 'luna'@'192.168.48.132' IDENTIFIED BY 'Luna@456';
CREATE USER 'luna'@'192.168.48.132' IDENTIFIED WITH mysql_native_password BY 'Luna@456';
  • First Statement: Uses MySQL 8.0+ default caching_sha2_password, which is more secure but requires TLS for remote access.
  • Second Statement: Uses legacy mysql_native_password, compatible with older MySQL clients and remote connections with out TLS.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.