Session1:
Mysql> Show create table T \g;
1. Row ***************************
Table:t
Create table:create Table ' t ' (
' id ' int (one) DEFAULT NULL,
' Name ' char ' DEFAULT NULL
) Engine=innodb DEFAULT Charset=utf8
1 row in Set (0.00 sec)
ERROR:
No query specified
mysql> lock table T read;
Query OK, 0 rows affected (1 min 3.82 sec)
Mysql> Show open tables from test;
+----------+-------+--------+-------------+
| Database | Table | In_use | name_locked |
+----------+-------+--------+-------------+
| Test | T | 1 | 0 |
| Test | T1 | 0 | 0 |
+----------+-------+--------+-------------+
2 rows in Set (0.00 sec)
Mysql> select * from T;
+------+------+
| ID | name |
+------+------+
| 1 | AAAA |
| 2 | BBB |
| 3 | DDD |
| 4 | TTT |
+------+------+
4 rows in Set (0.00 sec)
Mysql> select * from T1;
ERROR 1100 (HY000): Table ' T1 ' is not locked with LOCK TABLES
Mysql> Update T set name= ' a ';
ERROR 1099 (HY000): Table ' t ' is locked with a READ lock and can ' t is updated
mysql> INSERT INTO T1 values (1, ' AA ');
ERROR 1100 (HY000): Table ' T1 ' is not locked with LOCK TABLES
mysql> Delete from T1;
ERROR 1100 (HY000): Table ' T1 ' is not locked with LOCK TABLES
Mysql> insert INTO t values (5, ' e ');
ERROR 1099 (HY000): Table ' t ' is locked with a READ lock and can ' t be updated
mysql> update t set name= ' C '; ERROR 1099 (HY000): Table ' t ' is locked with a READ lock and can ' t is updated
mysql> delete from T;
ERROR 1099 (HY000): Table ' t ' is locked with a READ lock and can ' t is updated
In opening a sesion2:
Mysql> select * from T;
+------+------+
| ID | name |
+------+------+
| 1 | AAAA |
| 2 | BBB |
| 3 | DDD |
| 4 | TTT |
+------+------+
4 rows in Set (0.00 sec)
Mysql> select * from T1;
+------+------+
| ID | name |
+------+------+
| 1 | A |
| 2 | B |
| 3 | D |
| 3 | D |
+------+------+
4 rows in Set (0.00 sec)
mysql> Delete from T1 where id=3;
Query OK, 2 rows affected (0.03 sec)
Mysql> select * from T1;
+------+------+
| ID | name |
+------+------+
| 1 | A |
| 2 | B |
+------+------+
mysql> INSERT INTO T1 values (3, ' d ');
Query OK, 1 row affected (0.03 sec)
2 rows in Set (0.00 sec)
Mysql> INSERT into t values (3, ' d ');
Jammed
Mysql> Delete from T;
Jammed
Update T set name= ' a ';
Jammed
Conclusion: It is usually session1 because a process locks T and wants to access another T1 when the lock is not released, the error 1100 (HY000) is reported: Table ' T1 ' is not locked with LOCK TABLES
in MySQL, if a session uses lock table Tname Read|write to lock a table,
then the same session can only query the locked table, can not update the locked table Insert Delete, do not allow the table is not locked query update insert Delete, the other session on the locked table can only query, can not update, Insert,delete operation
other sessions are still available for SELECT, Update, insert, and delete operations on tables that are not locked