[MySQL] InnoDB Transaction – 交易指南 (SELECT … FOR UPDATE)

鎖資料列(可讀/不可讀)

MySQL Document 14.5.2.4 Locking Reads

主要分為sharedLock與lockForUpdate:

sharedLock locks only for write, lockForUpdate also prevents them from being selected

Pessimistic Locking (SELECT … FOR UPDATE)

談到pessimistic concurrency control(Lock row for read),實作上再Transaction內使用:

SELECT ... FOR UPDATE

則結果列將會被鎖定且不可讀,應用上可做不重複流水號等等。

Leave a Reply

Your email address will not be published. Required fields are marked *