Farmers in yards world, beautiful application experience, from the programmer for the processing of detail, and self requirements state, agriculture in the yard a member of the young people is busy, every day, every week, can leave some footprints, is the creation of content, there is a persistent, is I don’t know why, if you lost, might as well to Chou Chou code track of farmers.
- Beautiful musical beats take you through the coding process of this effect
- Insist on every day, is the pursuit of every ideal youth
- Follow in the footsteps of young people, and maybe your answer is right here
- Take a look here if you’re confused
1 introduction
As shown below, a normal update statement
update tb_user set ranking='Y' where user_id='760'
Copy the code
When you click execute, you will see:
Do you know what happened??
The following figure shows the execution of a query statementClick here for details During the execution of the update statement, it is also necessary to follow the basic process as shown in the figure above.
The execution of an update command
- The first step is to find the engine to fetch the line user_id=’760′. Where user_id is the primary key, the engine finds this row directly using tree search. If the line user_id=’760′ is already in memory, it is returned directly to the executor. Otherwise, you need to read into the memory from disk and then return.
- In the second step, the actuator takes the row data given by the engine, modifies the value of the corresponding column, and then obtains a new row of data, and then calls the engine interface to write the new row of data.
- Step 3 The engine updates the new row to memory and logs the update to the redo log.
- Step 4 the executor generates a binlog of the operation and writes the binlog to disk.
- In step 5, the executor calls the commit transaction interface of the engine, and the engine changes the redo log to commit
State, the update is complete.
3 MySql WAL technology
3.1 Redo log
When a record needs to be updated, the InnoDB engine writes the record to the redo log, updates the DATABASE operation engine memory, and then updates it to disk when the system is idle. This process can be described as WAL.
WAL stands for write-Ahead Logging. The key point is to Write logs first and then disks.
Redo log allows InnoDB to ensure that all previously committed records are not lost in the event of an abnormal database restart. This capability is called crash-safe.
3.2 binlog log
MySQL as a whole includes two parts, one is the Service layer:The second part is the engine layer, which stores related functions. The redo log is the InnoDB data storage engine specific log, and the binlog archive log is the Server layer held log.
3.3 Differences between Redo log and binlog
- Redo logs are InnoDB logs, binlogs are Server logs
- The redo log is a physical log of what was changed on a data page. The binlog is a logical log that records the original logic of the statement, such as the update statement here
- Redo logs are written in a circular manner, and binlogs are appended. A binlog file changes to a specified size without overwriting the previous log file.
The completion of
Not limited to thinking, not limited to language restrictions, is the highest realm of programming.
With xiaobian character, must be to record a set of video, and then upload
If you are interested, you can check out the watermelon video – early risers