set autocommit=0; select * from role where seat=98 for update;
这里注意,set autocommit=0是必不可少的,因为如果数据很快就提交的话,锁就会自动释放。 www.atcpu.com 再发一条sql查询:select * from role where id = 1; 显示结果: +----+--------+------+ | id | name | seat | +----+--------+------+ | 1 | 管理员 | 98 | +----+--------+------+ 1 row in set (0.00 sec)
这是因为select 操作 无关乎锁定。 www.atcpu.com 然后看写操作:update role set seat=99 where id =3;