MYSQL优化(2)——mysql锁
MYSQL优化(2)——mysql锁
MYSQL优化(2)——mysql锁
在这里插入图片描述
MYSQL优化(2)——mysql锁
MYSQL优化(2)——mysql锁
MYSQL优化(2)——mysql锁
1.lock table testmysam READ 启动另外一个session select * from testmysam 可以查询
2. insert into testmysam value(2); update testmysam set id=2 where id=1; 报错
3.在另外一个session中 insert into testmysam value(2); 等待
4.在同一个session中 insert into testdemo value(2,‘2’,‘3’); 报错 select * from testdemo ; 报错
5.在另外一个session中 insert into testdemo value(2,‘2’,‘3’); 成功
6.加索在同一个session 中 select s.* from testmysam s 报错lock table 表名 as 别名 read;
7. 查看 show status LIKE ‘table_locks_waited’ 表被锁过几次
MYSQL优化(2)——mysql锁
1.lock table testmysam WRITE 在同一个session中 insert testmysam value(3); delete from testmysam where id = 3 select * from testmysam
2.对不同的表操作(报错) select s.* from testmysam s insert into testdemo value(2,‘2’,‘3’);
3.在其他session中 (等待) select * from testmysam
MYSQL优化(2)——mysql锁
MYSQL优化(2)——mysql锁
MYSQL优化(2)——mysql锁
1.BEGIN select * from testdemo where id =1 for update 在另外一个session中 update testdemo set c1 = ‘1’ where id = 2 成功 update testdemo set c1 = ‘1’ where id = 1 等待
2.BEGIN update testdemo set c1 = ‘1’ where id = 1 在另外一个session中 update testdemo set c1 = ‘1’ where id = 1 等待
3.BEGIN update testdemo set c1 = ‘1’ where c1 = ‘1’ 在另外一个session中 update testdemo set c1 = ‘2’ where c1 = ‘2’ 等待
MYSQL优化(2)——mysql锁
1.先来看下行锁 第一个session中 select * from testdemo where id =1 for update 第二个session select * from testdemo where id =1 lock in share mode 回到第一个session UNLOCK TABLES 并不会解锁 使用commit 或者 begin或者ROLLBACK 才会解锁
2.再来看下表锁 lock table testdemo WRITE 使用commit,ROLLBACK 并不会解锁 使用UNLOCK TABLES 或者begin会解锁
MYSQL优化(2)——mysql锁
perl F:\BaiduNetdiskDownload\vip\pt-online-schema-change h=127.0.0.1,p=root1234%,u=root,D=mysqldemo,t=product_info --alter "modify product_name varchar(150) not null default ‘’ " --execute

相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2021-06-18
  • 2021-11-17
  • 2021-07-04
  • 2021-10-15
  • 2022-12-23
相关资源
相似解决方案