当前位置:网站首页>MySQL master-slave replication
MySQL master-slave replication
2022-07-06 03:51:00 【Li Jue】
Why copy ?
- Prevent accidental loss of data , Make users suffer losses .
- A machine is down , You can enable the backup of data on another machine .
- The probability of downtime is very small , Spare time can also allow the backup machine to share the flow pressure of the main machine .
- When upgrading the database version , The standby machine can be upgraded preferentially without stopping the user service , Upgrade the main database after observing its availability and stability .
Can't always let DBA Copy manually to complete the replication , So we still need to design a mechanism that can automatically copy .
Design replication mechanism
Our tentative replicated database is the main database , Pasted from the Library , To realize the replication from master library to slave Library , It looks very simple , Just one planning task , Regularly copy a copy of the main database data file , And transfer it to the server where the slave library is located .
But after all, scheduled tasks are not real-time , In case the main database fails ten minutes after the last replication , The activated slave library uses the last copied data , So ten minutes of data will be missing , The consequences are unimaginable .
Or do you want to copy in real time , That can be like this , The master library sends the executed statements to the slave Library in real time , Let the slave execute immediately , It can ensure the consistency of data on both sides .
The bad thing is , The master database sends data to the slave database in real time , You need to wait for the execution of the slave library to process the next statement , It seriously takes up the execution time of the main library , If there are too many libraries , The main warehouse is abandoned .
It has to be changed to asynchronous to save the time of the main database , You can save the executed statements of the main library into a file , Let's get it from the library , In this way, the master database does not have to wait for the slave database . Since it is written to the file , The speed is very fast , The main library can write statements to files before execution , Achieve higher synchronization efficiency .
Some of the above problems , It is impossible to run to the main database to get data from the database , Only one thread can be started to establish a connection with the main library , And ask for data from the main database , Then the main library also starts a thread to read the contents of the file , And push it to the slave thread , After receiving the statement from the library, it can be executed immediately .
Such efficiency is still very low , The thread of the main library cannot push another one until the statement is received and executed from the Library , If there are multiple slave Libraries , The master library needs to open multiple threads to keep communicating with each slave library for a long time , Occupy the main library server resources , It's better to create a file from the library to temporarily save the statements sent from the main library , Save it first and then execute it slowly , The pressure of the main reservoir is reduced , Rest assured from the Library .
Now I have my own file from the library as a relay , Don't worry , You can start another thread from the Library , Slowly execute the statements in the relay file , After the implementation, the original document has no value , You can clean it up , Avoid occupying server resources .
up to now , The most basic replication mechanism is designed , This way of copying from master database to slave database is a typical master-slave architecture , On this basis, evolution can be carried out , For example, there are many from the Library , The master database should push data for each slave database , The pressure of the main reservoir will increase , And because the main database is not only responsible for synchronizing data , Also busy reading and writing data , So people can replace the synchronization of data , For example, establish a master database between the master database and the slave database , The only responsibility of the newly established master database is to synchronize data to the slave database , In this way, the real master database only needs to push data to the new master database once , You can read and write data at ease in the rest of the time .
边栏推荐
- 简易博客系统
- 在 .NET 6 中使用 Startup.cs 更简洁的方法
- Why do you want to start pointer compression?
- Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- 51nod 1130 n factorial length V2 (Stirling approximation)
- 简述C语言中的符号和链接库
- Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
- [American competition] mathematical terms
- BUAA计算器(表达式计算-表达式树实现)
猜你喜欢

3.1 rtthread 串口设备(V1)详解

STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
![[slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board](/img/07/973722bf484b374f752177dfc48ef5.png)
[slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board

WPF effect Article 191 box selection listbox

RT thread -- FTP of LwIP (2)

LTE CSFB test analysis

C#(二十七)之C#窗体应用

简易博客系统

2.2 STM32 GPIO operation

Alibaba testers use UI automated testing to achieve element positioning
随机推荐
[Key shake elimination] development of key shake elimination module based on FPGA
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
C (XXIX) C listbox CheckedListBox Imagelist
Blue Bridge Cup - day of week
C#(三十一)之自定义事件
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Chinese brand hybrid technology: there is no best technical route, only better products
Blue style mall website footer code
Svg drag point crop image JS effect
阿里测试师用UI自动化测试实现元素定位
[rust notes] 18 macro
Mathematical modeling regression analysis relationship between variables
多项目编程极简用例
UDP reliable transport protocol (quic)
BUAA calculator (expression calculation - expression tree implementation)
[Qt5] QT QWidget immediately appears and disappears
Flask learning and project practice 8: introduction and use of cookies and sessions
1、工程新建
Proof of Stirling formula
【FPGA教程案例11】基于vivado核的除法器设计与实现