for update 是手工加锁操作,使用方法select...for update,在mysql中,如果查询条件带有主键,会锁行数据,如果没有,会锁表。直到事务提交或回滚后为止。
例1:select * from user where name='' for update;(锁表)
例2:select * from user where id=1 for update;(锁行id=1的数据)
例3:select * from user where id=-1 for update;(id不存在,锁表)