When building a server, the database can be said to be the bottleneck of the server , When the server pressure is high, most of the bottlenecks are caused by the database , Therefore, in order to solve the problem of high concurrency, it is possible to expand the capacity of multiple computers mysql The server , Then there will be a problem at this time , How can data read and write be synchronized between multiple servers ?

We can use it mysql Master slave replication solves this problem , In other words, one master server implements write operation, and multiple slave servers realize read operation , The data of the slave server is consistent with that of the master server , In this way, when high concurrency occurs, the pressure on the server will be less .
The master-slave server can be divided into several types , One master and one subordinate , One master and many subordinates , Multi master and multi subordinate
Here is the most simple one master and one slave
1. The first thing to do is to set up two servers and install them mysql, I am here at VMware Two virtual machines installed on , The system is Centos 7
Start the mysql service

2. Turn off the firewall and selinux
systemctl stop firewalld.service && systemctl disable firewalld.service
setenforce 0
3. modify /usr/local/mysql/my.cnf
server_id = 1# The host can be set to 1, The slave can be set to IP last leg ( Guarantee uniqueness )
log_bin=mysql-bin # The core of master-slave service
systemctl resatrt mysql.servicec# Restart the server
4. The databases and tables on the master and slave servers are consistent
1. Log in to the database server
mysql -uroot -p
2. Create test database
create database test;
3. choice test database
use test;
4. Create a data table for the master-slave test user
create table user(id int(11) auto_increment primary key, name varchar(30)
)engine=innodb,default charset=utf8;
5. Master slave server configuration ( Create an account to synchronize data )
grant replication slave on . to ‘mysync’@’%’ identified by ‘12345678’;

all privileges: Indicates that all permissions are granted to the user . Specific permissions can also be specified , as :SELECT,CREATE,DROP etc .

on: Indicates which databases and tables these permissions are in effect for , format : Database name . Table name , It's written here “*” Represents all databases , All tables . If I want to specify that permissions should be applied to test Library's user In the table , It can be written like this :test.user

to: To which user are permissions granted . format :” user name ”@” Sign in IP Or domain name ”.% There are no restrictions , You can log in on any host . such as :”yangxin”@”192.168.0.%”, express yangxin This user can only use 192.168.0IP Duan login
identified by: Specifies the login password of the user
with grant option: Indicates that a user is allowed to authorize his own permissions to other users

flush privileges;# Refresh permissions
show master status; # View status , Do not do anything after that
It is shown below , among File and Position Value is used to configure the slave server

6. Configure from the server
change master to
[File] and [Position] It should be consistent with the host status shown in the figure above
start slave;# Open slave service

Slave_IO_Running: Yes # Responsible for the io signal communication
Slave_SQL_Running: Yes # Take charge of your own slave mysql process

The problem here is when you start from the server Slave_IO_Running Always for no, The blogger checked the error log and found that the reason was Fatal error: The slave I/O
thread stops because master and slave have equal MySQL server UUIDs; these
UUIDs must be different for replication to
work. That's every one of them mysql example UUID(UUID Save in datadir Directory auto.cnf In the file ) It's not unique , The reason why there are such problems , It's because my slave host is the host of the cloned master library , therefore auto.cnf Saved in file UUID There will be repetition , The solution is to stop the standby database instance , Delete the auto.cnf file , Start the standby database instance , At this time, the standby database will generate a new auto.cnf file ( Produce new UUID)

7. Insert data test on the master server
insert into user(name) values(‘ Xiaojie ’);

View from server
select * from user;

©2019-2020 Toolsou All rights reserved,
Forbes China Auto rich list : He xiaopengdi 11 Li Xiangdi 14 Li Bindi 15 Change one's mind ! Tesla starts to deliver made in China to European market Model 3 The difference between memory overflow and memory leak , Causes and Solutions Character recognition technology of vehicle license plate based on Neural Network Vue Transfer parameters and receiving of page Jump SparkSQL Achieve partition overlay write 1190 Reverses the substring between each pair of parentheses leetcode Note 14 : The second biggest obstacle to motivating others in R & D management Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type