Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the necessity and category of locks in MySQL

Shulou Source: shulou.com Published: 2022-06-01 17:51:01 10月06日 Update

The following mainly brings you the necessity and categories of locks in MySQL. I hope these contents can bring you practical use, which is also the main purpose of my article on the necessity and categories of locks in MySQL. All right, don't talk too much nonsense, let's just read the following.

When the number of user visits increases, the database is often a performance bottleneck of the system, but not only the performance bottleneck, but also data security will emerge, at this time the locking mechanism is very necessary.

The data security problems caused by concurrency are mainly divided into three aspects: dirty reading, phantom reading and unrepeatable reading.

one。 Dirty reading

Dirty reading is when one transaction reads uncommitted data from another transaction.

Timeline transaction 1 transaction 2 1 begin; 2 select * from lock where id = 1; 3 begin; 4 update lock set name='dirty'; 6 select * from lock where id = 1; 7 commit Commit

two。 Illusory reading

Phantom reading is when one transaction reads the data of another transaction insert

Timeline transaction 1 transaction 2 1 begin; 2 select * from lock where id > 1; 3 begin; 4 insert lock select 2; 5 commit 6 select * from lock where id > 1; 7 commit

three。 Non-repeatable

Non-repeatable reading means that the results returned from multiple readings of unified data are inconsistent. Unlike dirty reading, this is reading data that has been submitted; unlike phantom reading, this is updated data, and phantom reading is inserting data.

Timeline transaction 1 transaction 2 begin; select * from lock where id = 1; begin; update lock set name='non-rr'; commit; select * from lock where id = 1 Commit

MySQL solves the above three problems by isolating transactions.

There are four levels of isolation.

Isolation level dirty read phantom read non-repeatable read uncommitted read (RUC) committed read (RC) whether it is repeatable read (RR) No serializable No

MySQL implements transaction isolation through locking mechanism.

The categories of locks are as follows

For the above about the necessity and types of locks in MySQL, do you think it is very helpful? If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

Tags: Transaction data necessity isolation necessity category content that is time difference security following performance mechanism bottleneck level problem consistency reality nonsense Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL Shulou Information OPPO Reno Linux