Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand read commited and repeatable read in mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to understand read commited and repeatable read in mysql". In daily operation, I believe many people have doubts about how to understand read commited and repeatable read in mysql. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to understand read commited and repeatable read in mysql"! Next, please follow the editor to study!

Two things, An and B

1. Let's take a look at the read committed level:

-- A thing

Mysql > set session transaction isolation level read committed

Query OK, 0 rows affected (0.00 sec)

Mysql > set autocommit = 0

Query OK, 0 rows affected (0.01 sec)

Mysql > begin

Query OK, 0 rows affected (0.00 sec)

Mysql > select * from test

+-+ +

| | id | comm |

+-+ +

| | 1 | aaa |

+-+ +

1 row in set (0.00 sec)

-- B things

Mysql > set autocommit = 0

Query OK, 0 rows affected (0.00 sec)

Mysql > begin

Query OK, 0 rows affected (0.00 sec)

Mysql > update test set comm = 'bbb' where id = 1

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

-- A thing queries table test at this time, while B thing is not submitted, so what you read is still old data.

Mysql > select * from test

+-+ +

| | id | comm |

+-+ +

| | 1 | aaa |

+-+ +

1 row in set (0.00 sec)

-- B things submitted

Mysql > commit

Query OK, 0 rows affected (0.00 sec)

-- A things are queried again, and the data has changed.

Mysql > select * from test

+-+ +

| | id | comm |

+-+ +

| | 1 | bbb |

+-+ +

1 row in set (0.00 sec)

It can be seen that at the read committed level, as the name implies, in the course of the transaction, the A thing cannot read the unsubmitted data of the B transaction, but it can read the data modification that the B transaction has submitted.

two。 Let's look at the repeatable read level.

-- A thing:

Mysql > set autocommit = 0

Query OK, 0 rows affected (0.00 sec)

Mysql > set session transaction isolation level repeatable read

Query OK, 0 rows affected (0.00 sec)

Mysql > begin

Query OK, 0 rows affected (0.00 sec)

Mysql > select * from test

+-+ +

| | id | comm |

+-+ +

| | 1 | aaa |

+-+ +

1 row in set (0.00 sec)

-- B things:

Mysql > set autocommit = 0

Query OK, 0 rows affected (0.00 sec)

Mysql > begin

Query OK, 0 rows affected (0.00 sec)

Mysql > update test set comm = 'bbb' where id = 1

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

-- A thing queries table test at this time, while B thing is not submitted, so what you read is still old data.

Mysql > select * from test

+-+ +

| | id | comm |

+-+ +

| | 1 | aaa |

+-+ +

1 row in set (0.00 sec)

-- B things submitted

Mysql > commit

Query OK, 0 rows affected (0.00 sec)

-- A thing queried again and found that the data had not changed.

Mysql > select * from test

+-+ +

| | id | comm |

+-+ +

| | 1 | aaa |

+-+ +

1 row in set (0.00 sec)

It can be seen that at the repeatable read level, as the name implies, things A cannot read the uncommitted and committed data modifications of things B in the process of things.

For the repeatable read level, the transaction can only read the data at the beginning of the transaction, so the data read during the process of the transaction is consistent, while for the read commited level, the data read may be inconsistent during the progress of the transaction.

At this point, the study on "how to understand read commited and repeatable read in mysql" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report