在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

怎么进行MySQL 5.5 MyISAM表锁测试

143次阅读
没有评论

共计 4829 个字符,预计需要花费 13 分钟才能阅读完成。

这篇文章给大家介绍怎么进行 MySQL 5.5 MyISAM 表锁测试,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

对于 MyISAM 表,加的锁是表级锁;写操作会阻塞读操作,读操作会阻塞写操作,写操作会阻塞写操作;读操作不会阻塞读操作。

测试一,会话①的读操作阻塞会话②的写操作
会话①
mysql create table t2(id tinyint(3) unsigned not null auto_increment,
    –  name varchar(10) not null,
    –  primary key(id))
    –  engine=myisam auto_increment=8 default charset=gbk;
Query OK, 0 rows affected (0.03 sec)
mysql insert into t2(name) values(Neo
Query OK, 1 row affected (0.03 sec)
mysql insert into t2(name) values(Trinity
Query OK, 1 row affected (0.00 sec)

mysql select * from t2;
+—-+———+
| id | name    |
+—-+———+
|  8 | Neo     |
|  9 | Trinity |
+—-+———+
2 rows in set (0.00 sec)

mysql desc t2;
+——-+———————+——+—–+———+—————-+
| Field | Type                | Null | Key | Default | Extra          |
+——-+———————+——+—–+———+—————-+
| id    | tinyint(3) unsigned | NO   | PRI | NULL    | auto_increment |
| name  | varchar(10)         | NO   |     | NULL    |                |
+——-+———————+——+—–+———+—————-+
2 rows in set (0.09 sec)

为表增加读锁
mysql lock table t2 read;
Query OK, 0 rows affected (0.00 sec)

会话②
mysql select * from t2;
+—-+———+
| id | name    |
+—-+———+
|  8 | Neo     |
|  9 | Trinity |
+—-+———+
2 rows in set (0.00 sec)

会话会处于等待状态
mysql update t2 set name= James where id=5;

会话①
mysql show processlist;
+—-+—————–+———–+——+———+——–+—————————————————————————–+—————————————+
| Id | User            | Host      | db   | Command | Time   | State                                                                       | Info                                  |
+—-+—————–+———–+——+———+——–+—————————————————————————–+—————————————+
|  1 | system user     |           | NULL | Connect | 748155 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL                                  |
|  2 | system user     |           | NULL | Connect | 748156 | Connecting to master                                                        | NULL                                  |
| 13 | event_scheduler | localhost | NULL | Daemon  | 600105 | Waiting on empty queue                                                      | NULL                                  |
| 74 | neo             | localhost | fire | Query   |      0 | NULL                                                                        | show processlist                      |
| 75 | neo             | localhost | fire | Query   |     83 | Waiting for table level lock                                                | update t2 set name= James where id=5 |
+—-+—————–+———–+——+———+——–+—————————————————————————–+—————————————+
5 rows in set (0.00 sec)

mysql unlock tables;
Query OK, 0 rows affected (0.00 sec)

会话②
mysql update t2 set name= James where id=5;
Query OK, 0 rows affected (1 min 48.96 sec)
Rows matched: 0  Changed: 0  Warnings: 0

测试二,会话①的写操作阻塞会话②的读操作

会话①
mysql lock table t2 write;
Query OK, 0 rows affected (0.00 sec)

mysql insert into t2(name) values(Jack
Query OK, 1 row affected (0.01 sec)

mysql commit;
Query OK, 0 rows affected (0.00 sec)

mysql show processlist;
+—-+—————–+———–+——+———+——–+—————————————————————————–+——————+
| Id | User            | Host      | db   | Command | Time   | State                                                                       | Info             |
+—-+—————–+———–+——+———+——–+—————————————————————————–+——————+
|  1 | system user     |           | NULL | Connect | 748422 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL             |
|  2 | system user     |           | NULL | Connect | 748423 | Connecting to master                                                        | NULL             |
| 13 | event_scheduler | localhost | NULL | Daemon  | 600372 | Waiting on empty queue                                                      | NULL             |
| 74 | neo             | localhost | fire | Query   |      0 | NULL                                                                        | show processlist |
| 75 | neo             | localhost | fire | Query   |      2 | Waiting for table metadata lock                                             | select * from t2 |
+—-+—————–+———–+——+———+——–+—————————————————————————–+——————+
5 rows in set (0.00 sec)

会话②
查询会阻塞
mysql select * from t2;

会话①
mysql unlock tables;
Query OK, 0 rows affected (0.00 sec)

会话②
mysql select * from t2;
+—-+———+
| id | name    |
+—-+———+
|  8 | Neo     |
|  9 | Trinity |
| 10 | Jack    |
+—-+———+
3 rows in set (47.89 sec)

当同一个会话中,锁定一张表后,查询另外一张表会报错
mysql lock table test read;
Query OK, 0 rows affected (0.00 sec)

mysql select * from test where id=80;
+——+——+
| id  | name |
+——+——+
|  80 | Lily |
+——+——+
1 row in set (0.00 sec)

mysql select * from t70;
ERROR 1100 (HY000): Table t70 was not locked with LOCK TABLES

使用表的别名会报错
mysql lock table test read;
Query OK, 0 rows affected (0.00 sec)

mysql select * from test t where id=80;
ERROR 1100 (HY000): Table t was not locked with LOCK TABLES

需要对别名进行锁定

mysql lock table test t read;
Query OK, 0 rows affected (0.00 sec)

mysql select * from test t where id=80;
+——+——+
| id  | name |
+——+——+
|  80 | Kame |
+——+——+
1 row in set (0.00 sec)

关于怎么进行 MySQL 5.5 MyISAM 表锁测试就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计4829字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 成人在色线视频在线观看免费大全 | 中文字幕在线无码一区二区三区 | 国产一级影视 | 99视频精品全部免费观看 | 毛片线看免费观看 | 男人狂桶女人出白浆免费视频 | 一二三四国语在线观看视频 | 国产六月婷婷爱在线观看 | 一本毛片 | 亚洲蜜芽在线精品一区 | 曰本女人一级毛片看一级毛 | 日本亚洲欧美在线 | 亚洲欧美乱综合图片区小说区 | 亚洲精品无码你懂的 | 欧美在线视频免费观看 | 亚洲免费三区 | 东京无码熟妇人妻av在线网址 | 欧美丰满熟妇aaaaa片 | 亚洲av无码专区在线播放中文 | 老熟女重囗味hdxx70星空 | 日韩毛片无码永久免费看 | 大桥未久亚洲无av码在线 | 国产又猛又黄又爽 | 色老板美国在线观看 | 久久综合99 | 色在线视频观看 | 国产亚洲精品久久久久久久软件 | 欧美成人激情在线 | 99久9在线 | 免费 | 一个人免费看www视频 | 一区二区高清视频 | 亚洲欧美自拍色综合图 | 久久久www成人免费精品 | 18禁免费无码无遮挡不卡网站 | 天天干天天色 | 国产激烈床戏无遮挡在线观看 | 午夜视频免费在线 | 在线观看成人小视频 | 国产午夜高清一区二区不卡 | 国产精品美女久久久久av福利 | 欧美、另类亚洲日本一区二区 |