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 add Row Lock in mysql

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

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to add mysql row lock, I hope you will learn a lot after reading this article, let's discuss it together!

Create a row lock condition:

1. Create an index in the table, select. The where field (must be an index) or the row lock is invalid.

2. There must be a transaction, which is the row lock (exclusive lock).

3. Add FOR UPDATE after the select statement

Example: to test whether a lock is added, execute 1 and then 2

Query 1

START TRANSACTION; # plus transaction SELECT UserID,Password,Age FROM AccountsDB.Accounts_InFo WHERE Accounts = 'hello2' FOR UPDATE; # locked select SLEEP (5); # Sleep COMMIT; # commit

Query 2:

START TRANSACTION; SELECT UserID,Password,Age FROM AccountsDB.Accounts_InFo WHERE Accounts = 'hello2' FOR UPDATE;COMMIT; after reading this article, I believe you have a certain understanding of mysql how to add row locks, want to know more about it, welcome to follow the industry information channel, thank you for reading!

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

Database

Wechat

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

12
Report