当前位置:网站首页>Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
2022-07-31 03:18:00 【Kong Tom】
One. The basic principle of MySQL master and backup
Active-standby switching process:
- The client's read and write directly access node A, and node B is the standby database of A. It just synchronizes the updates of A and executes it locally, so that the data of nodes B and A are kept the same
- Switch to state 2, the client read and write access to node B, and node A is the standby database of B
Set Node B (standby database) to readonly mode
- Some operational query statements will be placed in the backup database to check,Set read-only to prevent misuse;
- Prevent switching logic from bugs.Double writing occurs during the switching process, resulting in inconsistency between active and standby;
- readonly state, to determine the role of the node
Set standby to read-only, and follow The main library is kept up to date:
Because the readonly setting is invalid for super users, it is used for A thread that synchronizes updates has super permission.
Second, the UPDATE statement executes the steps of synchronizing to node B on node A:
- After the main library receives the follow-up request from the client, it executes the update logic of the internal transaction and writes the binlog at the same time
- A long connection is maintained between the standby database B and the primary database A.There is a special thread inside the main database A to serve the long connection of the standby database B
Three. The complete process of transaction log synchronization:
- Use the change master command on the standby database B to set the IP of the primary database A.Port, username, password and where to start requesting binlog, this location contains filename and log offset
- Execute the start slave command on the standby database B. At this time, the standby database will start two threads, namely io_thread and sql_thread in the figure.Among them, io_thread is responsible for establishing a connection with the main library
- After verifying the user name and password, the main database A starts to read the binlog from the local according to the location passed by the standby database B, and sends it to B
- After the standby database B gets the binlog, it writes it to the local file, which is called the relay log
- sql_thread reads the secondary school log, parses the commands in the log, and executes them.
边栏推荐
猜你喜欢
[C language] Preprocessing operation
想从手工测试转岗自动化测试,需要学习哪些技能?
11. Redis implements follow, unfollow, and follow and follower lists
7年经验,功能测试工程师该如何一步步提升自己的能力呢?
浅识Flutter 基本组件之CheckBox组件
The use of font compression artifact font-spider
6. Display comments and replies
MP使用时的几个常见报错
【C语言】进制转换一般方法
Project (5) - Small target detection tph-yolov5
随机推荐
[C language] Preprocessing operation
[Godot][GDScript] 2D cave map randomly generated
What is SQALE
Database implements distributed locks
SQL injection Less47 (error injection) and Less49 (time blind injection)
Compile Hudi
Office automation case: how to automatically generate period data?
C primer plus study notes - 8, structure
Chapter 9 SVM Practice
What skills do I need to learn to move from manual testing to automated testing?
点云DBSCAN聚类(MATLAB,非内置函数)
遗留系统的自动化策略
els 方块向右移
What is distributed and clustered?What is the difference?
Atomic operation CAS
SocialFi 何以成就 Web3 去中心化社交未来
想从手工测试转岗自动化测试,需要学习哪些技能?
Difference between unallocated blocks and unused blocks in database files
QML的使用
WebSocket Session is null