数据库锁

来源:互联网 发布:气体检测仪数据 编辑:程序博客网 时间:2024/06/06 13:05
  • 悲观锁

select * from test for update

  • 乐观锁
  • 读锁(共享锁)

所有的进程都只能对加锁对象进行读操作。下面以MySQL为例做测试:

lock tables student read; insert into student values (now(), "", "", "");

如果执行上面的两条SQL,就会得到这样的错误提示:[Err] 1099 - Table 'student' was locked with a READ lock and can't be updated

  • 写锁(排它锁、独占所)

只有加锁进程可以写入(或者读),其他进程不能做读、写操作。

查看原文:http://surenpi.com/2015/12/02/%e6%95%b0%e6%8d%ae%e5%ba%93%e9%94%81/

0 0
原创粉丝点击