当前位置:网站首页>3: MySQL master-slave replication setup
3: MySQL master-slave replication setup
2022-07-28 06:06:00 【Performer】
1: First, introduce the environment
Two alicloud servers : Master(34) Alibaba cloud Slave(226) Alibaba cloud
operating system :CentOS 7.9 64 position
Mysql edition :8.0.28
signal communication : Adopt Intranet IP
2: Installation per server Mysql
I wrote an article about installation before Mysql Tutorials available
3: Build master-slave replication
1: Construction of master node
(1): Edit profile
vim /etc/my.conf file , stay [mysqld] Add below
# Mysql Of bin-log Name
log-bin=mysql-bin
# Mysql Globally unique in the instance , And greater than 0
server-id=34
# Ban Mysql Server For external connections DNS analysis , Use this option to eliminate Mysql Conduct DNS Time of resolution . But all remote connections should use IP Address
skip_name_resolve=ON

(2): see binlog Open or not
restart mysql service , And connect mysql, see binlog Open or not
restart mysql service
systemctl restart mysqld
Inquire about binlog Open or not
show global variables like '%log%';

(3): see binlog Log list
show master logs;

(4): View the server-id Whether to take effect
show global variables like '%server%';

(5): Create a backup account on the primary node
create user 'username'@'%' identified by 'password';
GRANT REPLICATION SLAVE ON *.* TO 'username'@'%';
flush privileges;

2: Construction of slave nodes
(1): Edit profile
vim /etc/my.conf file , stay [mysqld] Add below
# relay log Many aspects and binary log almost , The difference lies in From node's I/O The thread reads the binary log of the main server and records it to the local file of the server , then SQL The thread will read relay-log The contents of the log are applied to the slave node , Thus, the data of the slave node and the master node are consistent
# Definition relay_log Location and name of
relay-log=relay-log
# Definition relay_log Location and name of
relay-log-index=relay-log.index
# Close from node binlog journal
skip-log-bin
# Mysql Globally unique in the instance , And greater than 0
server-id=226
# Ban Mysql Server For external connections DNS analysis , Use this option to eliminate Mysql Conduct DNS Time of resolution . But all remote connections should use IP Address
skip_name_resolve=ON
# You can modify InnoDB Is independent tablespace mode , Each table in each database generates a data space .
innodb_file_per_table=ON

(2): Check the relay log
restart mysql service , And connect mysql, Check whether the relay log is enabled
restart mysql service
systemctl restart mysqld
show global variables like '%log%';

(3): see server-id Whether to take effect
show global variables like '%server%';

(4): The slave node configures the master-slave connection information
The master node needs to find binlog Log the latest files and indexes
show master logs;
myster_log_file and master_log_pos Through the of the master node
Command view . Corresponding Log_name and File_size
Command from node
CHANGE MASTER TO MASTER_HOST='172.29.114.155',
MASTER_USER='username',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=875;

(5): Turn on synchronization
View synchronization status information
show slave status\G;

Turn on synchronization
start slave;

Check the status information again , So far, the master-slave replication configuration is completed 
4: test
Operation on the master node
create database mydb1;
show master status;
Main node diagram 
Operate from the node
show databases;
show slave status\G;
Slave node graph 
5: Some problems encountered
1: Close from node binlog
If it's not closed , Will result in invalid replication
vim /etc/my.cnf
# Set to off binlog
skip-log-bin
2: Connect master error , A secure connection is required
Error message
2022-03-07T08:41:23.047640Z 139 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 34 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061
The solution at that time :
stop slave; Close slave node
stay master Put this slave Delete the account , Re create the authorization and refresh it .
stay slave Do it again 【 Command from node 】 That's all right. .
3: I don't know where the error log is , There is no way to check
terms of settlement : from my.cnf find log-error Configuration item , Value is the error log
vim /etc/my.cnf
This is the path of the error log
log-error=/var/log/mysqld.log
4: It's restarted mysql after , You need to restart the read / write configuration from the node
start slave;
6:Java Application testing
(1): Using frames
SpringBoot(2.1.5.RELEASE)
Mybatis-Plus(3.3.0)
Sharding-Jdbc-spring-boot(4.0.0-RC2)
HikariCP(3.2.0)
(2): Success map

(3): Source code ( contain sql)
边栏推荐
猜你喜欢
随机推荐
Flink CDC (Mysql为例)
Two methods of covering duplicate records in tables in MySQL
数字藏品“大乱斗”,千亿市场变局将至?
1: Why should databases be divided into databases and tables
微信小程序开发语言一般有哪些?
2: Why read write separation
微信上的小程序店铺怎么做?
Distinguish between real-time data, offline data, streaming data and batch data
更新包与已安装应用签名不一致
MySQL trigger
It's not easy to travel. You can use digital collections to brush the sense of existence in scenic spots
flutter webivew input唤起相机相册
Structured streaming in spark
【一】redis简介
Assembly打包
出游不易,看景区用数字藏品刷存在感
How digital library realizes Web3.0 social networking
3:Mysql 主从复制搭建
自动定时备份远程mysql脚本
Invalid packaging for parent POM x, must be “pom“ but is “jar“ @








