您的位置:首页 > 数据库 > MySQL

mysql 锁表问题

2015-10-10 16:44 567 查看
最近项目用的mysql数据库,在多个表同时修改时遇到锁表的问题,

  测试得知,InnoDB在明确指定表主键id时才会执行ROwLock,否则执行表lock,

      select * from  table1  where id=1 for update; 此时会执行该行数据的lock

       select * from  table1  where name=1
 for update; select * from  table1  where id like '1%'
 for update; 此时执行的表lock;

      在mysql中可以启用事务自测。

      代码中,一般事务定义在服务层,在服务层中可以执行

 
          select * from  table1  where id=1 for update;

 
         update table1 set name=2 where id=1;

 
 这样可以在保证数据唯一性的前提下  修改数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: