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