当前位置:网站首页>MySQL master-slave replication
MySQL master-slave replication
2022-07-23 10:28:00 【amateur12】
Data can be obtained from a MySQL The database server master node is replicated to one or more slave nodes .
The master server is only responsible for writing , The slave server is only responsible for reading
species :
Master slave synchronization : When the user writes data, the master server must synchronize with the slave server to tell the user that the writing is successful , The waiting time is long .
Master slave asynchrony : As long as the user accesses the master server for writing data , Return to the user immediately .
Master slave semi synchronous : When the user accesses and writes data, the master server writes and synchronizes one of the slave servers, and then returns success to the user .
principle :
Data modification and writing master Database binlog in .
slave Of IO Threads copy these changes binlog To your own relay log in .
slave Of SQL The thread reads and reapplies relay log To your own database , Let it go together master Database consistency .
Log files :
Error log (error log): Record mysql Right and wrong information when starting and stopping the service , It also records the start of 、 stop it 、 Error messages during operation .
Query log (general log): Record established client connections and executed statements .
Binary log (bin log): Record all statements that change data , Can be used for Data replication .
Slow query log (slow log): Record all execution times over long_query_time All queries of or queries without index .
relay logs (relay log): Master slave copy Log used when .
advantage :
Provides the ability to separate reading and writing , send MySQL The database supports high concurrent read and write
It can improve the security of data , Effectively protect the data backup of physical server downtime
Insufficient :
Master-slave delay , Damage disaster tolerance , Because the data is out of sync
The reason for the master-slave delay
1、TPS When high , Produced DDL The quantity exceeds Slave One SQL Thread processing capability
2、Slave Medium and large Query Lock waiting occurs
How to judge whether there is a master-slave delay
show slave status -> Seconds_Behind_Master
How to avoid master-slave delay
1、 close Slave Of sync_binlog
2、 close Slave Of innodb_flushlog
3、 Performance ratio Master Better machines as Slave
4、 Set up one that does not provide query service Slave
5、 increase Slave The number of , Lower the unit Slave Reading pressure on
Interview answer :
MySQL It is a small and medium-sized relational database , It's based on Multithreading .
There are some bottlenecks in data storage and query speed , Read write separation is one of the solutions .
Main library write , Read from library .
Hang up the main warehouse , From the library, you can go up , Avoid the loss of downtime .
The principle of data synchronization is ,
Data modification and writing master Database binlog in .
slave Of IO Threads copy these changes binlog To your own relay log in .
slave Of SQL The thread reads and reapplies relay log To your own database , Let it go together master Database consistency .
There are also shortcomings. , There are delays and increased hardware purchase costs
The forms are ,
A master from
One master, many followers
Load Balancer ,
According to the algorithm , Which one to test MySQL Low pressure , Distribute the request to this station MySQL
Be similar to nginx Proxy service for
It can only relieve certain pressure , But it can't be cured .
Better than that redis, Memory based operations , Single threaded , Fast query speed .
边栏推荐
猜你喜欢

Customer first | domestic Bi leader, smart software completes round C financing

Redis transaction, lock mechanism, seckill

浏览安全怎么提升?教你设置安全浏览器信任站点

"Lost wake up problem" in multithreading | why do wait() and notify() need to be used with the synchronized keyword?

What is the difference between College coder and 985 programmer?

什么是即时通讯?即时通讯的发展

Kingbasees SQL language reference manual of Jincang database (8. Function (7))

The world is being devoured by open source software

S2SH+mysql的在线英语学习系统

How to improve browsing security? Teach you to set up a secure browser trust site
随机推荐
Is there a fraud in opening an account with Huatai Securities? Is it safe
redis伪集群一键部署脚本---亲测可用
Customer first | domestic Bi leader, smart software completes round C financing
32-spark的分区算子介绍、广播变量和累加器
Kingbasees SQL language reference manual of Jincang database (8. Function (7))
LeetCode每日一题(1946. Largest Number After Mutating Substring)
[vscode] the current working directory is not the current folder /pathlib print CWD path error
适合拼多多小商家配件的一些思路跟技巧
金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(六))
什么是文件管理软件?你为什么需要它?
Special training - linked list
performance介绍
【学习笔记】AGC022
CS5266+MA8621做TYPEC转HDMI+PD+U3+2U+SD/TF七合一拓展坞方案设计|CS5266多口拓展坞PCB+原理图参考
Performance introduction
客户至上 | 国产BI领跑者,思迈特软件完成C轮融资
[pytorch] the difference between cuda() and to (device)
How does the browser import and export | delete bookmarks? Here are the steps
金仓数据库 KingbaseES SQL 语言参考手册 (4. 伪列)
配饰器模式