Home > database > Mysql to update automatically locked, so optimistic locking in Mysql is how to achieve? Bothering me
Mysql to update automatically locked, so optimistic locking in Mysql is how to achieve? Bothering me
Time:10-09
Optimistic locking is not operating lock, but the default is locked? Optimistic locking is how to achieve that?? Can set the mysql to update this statement is not locked??
CodePudding user response:
Optimistic locking is to achieve in the program code
The table with a timestamp column First select id and the timestamp and then come out with id and the timestamp to update the row If failed to update the timestamp change, had been changed
CodePudding user response:
I confused the transaction and the definition of the lock before In mysql, for example: set in the optimistic locking is submitted automatically, which is a statement is a transaction, the transaction level may be submitted also can be read or uncommitted, Basic steps are: 1. Query the commodity information Select (status, the status, version) from t_goods where id=# {id} 2. According to the commodity information to generate the order 3. Modify the commodity status of 2 The update t_goods Set the status=2, version=version + 1 Where id=# # {id} and version={version}; Optimistic locking, each of the above statement is a small transaction, the select can be read casually, only when the update check, Don't know if I understand this???? Want to correct,,,