---创建表 回话一
mysql> create table t1 ( a int ,b char(2),c char(10));
Query OK, 0 rows affected (0.17 sec)mysql> insert into t1 values (1,1,1);
Query OK, 1 row affected (0.00 sec)mysql> insert into t1 values (2,2,2);
Query OK, 1 row affected (0.00 sec)mysql> insert into t1 values (3,3,3);
Query OK, 1 row affected (0.00 sec)mysql> begin -> ;
Query OK, 0 rows affected (0.00 sec)mysql> update t1 set a =a*10 where a =1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0---会话2
mysql> update t1 set a=20 where a=2;ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
由此可见,在inndb的存储类别下的表,支持行锁,但是没有主键的表,更新时会锁全部表的
通过创建普通索引 create index idx_a on t1(a); 重新操作,还是会锁表。
使用unique索引不会锁全表。