Row Level Locking in Mysql

前端 未结 2 1923
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 14:59

I have 5 rows in a table (1 to 5). I want row 2 lock for some update and in the meanwhile if someone tries to update row 4, then he should able to update.

I am trying th

2条回答
  •  逝去的感伤
    2021-02-15 15:33

    I found below option is more appropriate i generate 40000 numbers from concurrent session on the same time. I didnt found any duplicate number. Without below command i generate 10000 numbers and found 5 duplicate numbers.

    START TRANSACTION

    SELECT * FROM test WHERE t=1 FOR UPDATE;

    UPDATE test SET NAME='irfandd' WHERE t=2;

    COMMIT;

提交回复
热议问题