- mysql开启事务,默认上行锁,就是将这行数据锁住,只要事务没有提交,就禁止其他线程操作这行数据
- 例子:
创建行锁代码:
查看当前的行锁:@GetMapping("updateById") public int updateById(@RequestParam("id") Long id, @RequestParam("name") String name){ // 开启事务 但不提交 transactionUtils.begin(); // 根据id更新 UserEntity userEntity = new UserEntity(); userEntity.setId(id); userEntity.setUserName(name); userEntity.setAge(100); return userMapper.updateById(userEntity); }
select t.* from information_schema.innodb_trx t;
强制清除: kill 事务线程id;
kill 21;