???????????
????????????????????mysql??????????????????????????????洢?????????????????????磺myisam??memory?洢????????????????bdb??????????????????????????innodb?洢???漴????м??????????????????????????м?????
??????????????????1??????£?
??????1?????????????С??????????????????????????????????????????????????
??????2???м????????????????????????????????????С????????????????????????????
??????3????????? ??????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????á????м????????????д????????????????????????????????????????в??????????á?
????????myisam????
????1????????????????????????????????
????mysql> show status like 'table_lock%';
????+-----------------------+-------+
????| Variable_name         | Value |
????+-----------------------+-------+
????| Table_locks_immediate | 101   |
????| Table_locks_waited    | 0     |
????+-----------------------+-------+
????2 rows in set (0.00 sec)
????????????????????table_locks_waited????????????????????????????????????
????2?????????????
????mysql????????????????????????(table read lock)?????д??(table write lock)????????????????£?
????mysql?????????? none ???? д?? ???? ?? ?? ?? д?? ?? ?? ??
???????????myisam????????????????????????????????????????????????????д????.
??????myisam???д????????????????????????????д??????
????myisam??????????д??????????д???????????е??
????????????????????????
??????????????????????????????????±?????
????mysql> create table t18(id int auto_increment primary key??name varchar(63)??age int(3));
????Query OK?? 0 rows affected (0.33 sec)
????mysql> insert into t18(name??age)values('fzy1'??1)??('fzy2'??2)??('fzy3'??3);
????Query OK?? 3 rows affected (0.07 sec)
????Records: 3  Duplicates: 0  Warnings: 0
????mysql> select * from t18;
????+----+------+------+
????| id | name | age  |
????+----+------+------+
????|  1 | fzy1 |    1 |
????|  2 | fzy2 |    2 |
????|  3 | fzy3 |    3 |
????+----+------+------+
????3 rows in set (0.00 sec)
????д?????????? session_1 session_2 ????t18??write??
????mysql> lock table t18 write;
????Query OK?? 0 rows affected (0.00 sec)
???????session?????????????????£?????????????????
????mysql> insert into t18(name??age)values('fzy4'??4);
????Query OK?? 1 row affected (0.04 sec)
????mysql> update t18 set age=5 where id=2;
????Query OK?? 1 row affected (0.11 sec)
????Rows matched: 1  Changed: 1  Warnings: 0
????mysql> select * from t18;
????+----+------+------+
????| id | name | age  |
????+----+------+------+
????|  1 | fzy1 |    1 |
????|  2 | fzy2 |    5 |
????|  3 | fzy3 |    3 |
????|  4 | fzy4 |    4 |
????+----+------+------+
????4 rows in set (0.00 sec)
????????session??????????????????
????mysql> select * from t18;
???????
?????????
????mysql> unlock tables;
????Query OK?? 0 rows affected (0.00 sec)
??????? session2????????????????
????+----+------+------+
????| id | name | age  |
????+----+------+------+
????|  1 | fzy1 |    1 |
????|  2 | fzy2 |    5 |
????|  3 | fzy3 |    3 |
????|  4 | fzy4 |    4 |
????+----+------+------+
????4 rows in set (1 min 21.56 sec)
??????????д???? session_1 session_2 ???t18??read????
????mysql> lock table t18 read;
????Query OK?? 0 rows affected (0.00 sec)
???????session???????????
????mysql> select * from t18;
????+----+------+------+
????| id | name | age  |
????+----+------+------+
????|  1 | fzy1 |    1 |
????|  2 | fzy2 |    5 |
????|  3 | fzy3 |    3 |
????|  4 | fzy4 |    4 |
????+----+------+------+
????4 rows in set (0.00 sec)
????session_2???????????
????mysql> select * from t18;
????+----+------+------+
????| id | name | age  |
????+----+------+------+
????|  1 | fzy1 |    1 |
????|  2 | fzy2 |    5 |
????|  3 | fzy3 |    3 |
????|  4 | fzy4 |    4 |
????+----+------+------+
????4 rows in set (0.00 sec)
???????session??????δ??????????????????????????????????????
????mysql> select * from t17;
????ERROR 1100 (HY000): Table 't17' was not locked with LOCK TABLES
????????session???????????δ???????
????mysql> select * from t17;
????+----+------+------+--------+
????| id | name | age  | intro  |
????+----+------+------+--------+
????|  1 | fzy1 |    1 | intro1 |
????|  2 | fzy2 |    2 | intro2 |
????|  3 | fzy3 |    3 | intro3 |
????|  4 | hsq  |    4 | intro4 |
????+----+------+------+--------+
????4 rows in set (0.00 sec)
???????session?в????????????????
????mysql> insert into t18(name??age)values('fzy5'??5);
????ERROR 1100 (HY000): Table 't18' was not locked with LOCK TABLES
????????session???????????????????
????mysql> insert into t18(name??age)values('fzy6'??6);
???????
?????????
????mysql> unlock tables;
????Query OK?? 0 rows affected (0.00 sec)
??????? ????????
????Query OK?? 1 row affected (2 min 33.25 sec)