在这里插入图片描述
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’ 表被锁过几次
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
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’ 等待
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会解锁
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
相关文章: