如何给行加悲观锁(X排他锁)?

  1. start transction
  2. select * from table where id = 1 for update;
  3. update table set name = 'XX' where id = 1;
  4. commit;

X排他锁是否会阻塞普通查询?

我们知道X锁和S锁是互斥的。那么普通的select * from table where id = 1 是否会被阻塞呢?也就是说普通查询是否会加上共享锁呢?答案是不会,因为走的是快照读,不会加任何锁。
共享锁的语法是SELECT * FROMadminwhere id =1 lock in share mode;