当前位置:网站首页>MySQL master-slave replication solves read-write separation
MySQL master-slave replication solves read-write separation
2022-06-10 22:37:00 【Lingbeichen】
MySQL Master slave copy
The concept of separation of reading and writing
All the pressure of reading and writing is borne by one database , The data will be lost if the database service disk is damaged due to high pressure , A single point of failure

mysql Master-slave replication of can solve this problem
Introduce
MySQL Master-slave replication is an asynchronous replication process , The bottom layer is based on Mysql Binary log function of database . Just one or more Mysql database (slave, From the library ) From the other Mysql database (master, The main library ) Copy the log, then parse the log and apply it to itself , Finally, the data of the slave database is consistent with that of the master database .Mysql Principal and subordinate malfeasance is MySql The database has its own functions , No third party tools required .
mysql The replication process is divided into three steps
master Log changes to binary log (binary log)
slave take master Of binary log Copy to his relay log (relay log)
slave Redo relay log events , Apply the changes to your own database

To configure - precondition
Prepare two servers in advance , Install separately mysql And start the service successfully
Main library master
First step : modify Mysql Profile of the database /etc/my.cnf
[mysqld]
log-bin=mysql-bin #[ must ] Enable binary logging
server-id=100 #[ must ] The server is unique ID
The second step : restart mysql service
systemctl restart mysqld
The third step : Sign in Mysql database , Do the following SQL
GRANT REPLICATION SLAVE ON *.* to 'xiaoming'@'%' identified by '[email protected]';
notes : above SQL The role of is to create a xiaoming, The password for [email protected], And give xiaoming User grants REPLICATION SLAVE jurisdiction . It is often used to establish the user permissions required for replication , That is to say slave Must be master Authorize the user with this permission , Can be copied by this user .
Step four : Sign in mysql data , Do the following SQL, Record the results File and Position Value
show master status;
notes : above SQL View when Master The state of , After that SQL Do not perform any more operations
Slave Library slave
First step : modify mysql Profile of the database /etc/my.cnf
[mysqld]
server-id=100 #[ must ] The server is unique ID
The second step : restart mysql service
systemctl restart mysqld
The third step : Sign in Mysql database , Do the following SQL
change master to master_host='192.168.138.100',master_user='xiaoming',master_password='[email protected]',master_log_file='mysql-bin.000001',master_log_pos=439;
start slave;
Step four : Sign in Mysql database , Do the following SQL, View the status of the slave database
show slave status;
The cause of the error
1. The Internet is not working 2. The password is wrong 3.pos incorrect 4. The firewall is not off 5.server-id Conflict
If you use clone virtual machines , Must be modified mysql Of uuid, Otherwise it will show Slave_IO_Running: No
terms of settlement :
1. First of all mysql Installation address of
show variables like 'datadir';
# adopt MySQL Generate a uuid Recording, etc. will be used to modify
select uuid
2. Then enter datadir Catalog
cd /var/lib/mysql/
vi auto.cnf
Take what you have just prepared uuid Value substitution
3. restart mysql
systemctl start mysqld
边栏推荐
- Shell basic concepts
- Array intersection of two arrays II
- Opencv_100问_第四章 (16-20)
- leetcode 130. Surrounded regions (medium)
- [applet] vant sliding cell adds the function of clicking other positions to close automatically
- 笔记(五)- JVM
- (11) Tableview
- 很流行的状态管理库 MobX 是怎么回事?
- README
- SQL server queries are case sensitive
猜你喜欢

Differences between disk serial number, disk ID and volume serial number

Whale conference sharing: what should we do if the conference is difficult?

Visio 转为高质量PDF

数字孪生:第三人称鼠标操作

Tcapulusdb Jun · industry news collection (V)

Tcapulusdb Jun · industry news collection (IV)

Web3生态去中心化金融平台——Sealem Finance

Matlab - Implementation of evolutionary game theory

leetcode 130. Surrounded regions (medium)
![Add, delete, query and modify [MySQL] table data (DML)](/img/08/4239bc0486fe8db2e98e54919300b5.png)
Add, delete, query and modify [MySQL] table data (DML)
随机推荐
重排 (reflow) 与重绘 (repaint)
mathtype7.x的基本使用
TypeScript - 声明文件和内置对象
【问题】解决Websocket字符串长度限制问题单包过大
Variables (automatic variables, static variables, register variables, external variables) and memory allocation of C malloc/free, calloc/realloc
Whale conference empowers intelligent epidemic prevention
Basic use of mathtype7.x
dc_labs--lab1的学习与总结
Model construction of mmdetection
Management solution for whale conference smart scenic spot
Differences between disk serial number, disk ID and volume serial number
Notes (IV) - multithreading
SQLServer数据库应用与开发:第九章上机
罗永浩:我要是负责人 能让苹果产品上去三个台阶不止
【Py】接口签名校验失败可能是由于ensure_ascii的问题
修改SpriteMask 的 frontSortingLayer 变量
【TcaplusDB知识库】TcaplusDB事务管理介绍
Visio to high quality pdf
torch_geometric
[tcapulusdb knowledge base] tcapulusdb transaction management introduction