MySQL中的行級鎖SELECT FOR UPDATE 和LOCK IN SHARE MODE 區別

來源:互聯網
上載者:User

自己記錄一下,加深一下印象。英文資料來自於MySQL的官方文檔。中文為自己按照理解翻譯的。

      SELECT ... LOCK IN SHARE MODE sets a shared mode lock on the rows
read. A shared mode lock enables other sessions to read the rows but
not to modify them. The rows read are the latest available, so if they
belong to another transaction that has not yet committed, the read
blocks until that transaction ends.

在讀取的行上設定一個共用模式的鎖。這個共用鎖定允許其它session讀取資料但不允許修改它。 行讀取的是最新的資料,如果他被其它事務使用中而沒有提交,讀取鎖將被阻塞知道那個事務結束。

      SELECT ... FOR UPDATE sets an exclusive lock on the rows
read. An exclusive lock prevents other sessions from accessing the rows
for reading or writing.

在讀取行上設定一個獨佔鎖定。組織其他session讀取或者寫入行資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.