查看: 1208|回复: 2
|
Mysql > Lock Tables
[复制链接]
|
|
LOCK TABLES A WRITE ;# MySQL returned an empty result set (i.e. zero rows).
UPDATE A SET A_id=1;# Affected rows:285
UNLOCK TABLES ;# MySQL returned an empty result set (i.e. zero rows).
'# MySQL returned an empty result set (i.e. zero rows).'是指什么?
我用MyISAM,
我要做locking,有什么好介绍? |
|
|
|
|
|
|
|
发表于 14-7-2005 04:59 PM
|
显示全部楼层
请参考MYSQL本身的DOCUMENT. 在SECTION 7.3 Locking Issues.
The table-locking method MySQL uses for WRITE locks works as follows:
If there are no locks on the table, put a write lock on it.
Otherwise, put the lock request in the write lock queue.
The table-locking method MySQL uses for READ locks works as follows:
If there are no write locks on the table, put a read lock on it.
Otherwise, put the lock request in the read lock queue.
When a lock is released, the lock is made available to the threads in the write lock queue, then to the threads in the read lock queue.
This means that if you have many updates for a table, SELECT statements will wait until there are no more updates.
Starting in MySQL 3.23.33, you can analyze the table lock contention on your system by checking the Table_locks_waited and Table_locks_immediate status variables:
mysql> SHOW STATUS LIKE 'Table%';
+-----------------------+---------+
| Variable_name | Value |
+-----------------------+---------+
| Table_locks_immediate | 1151552 |
| Table_locks_waited | 15324 |
+-----------------------+---------+
If you want to do many INSERT and SELECT operations on a table when concurrent inserts are not possible, you can insert rows in a temporary table and update the real table with the records from the temporary table once in a while. This can be done with the following code:
mysql> LOCK TABLES real_table WRITE, insert_table WRITE;
mysql> INSERT INTO real_table SELECT * FROM insert_table;
mysql> TRUNCATE TABLE insert_table;
mysql> UNLOCK TABLES; |
|
|
|
|
|
|
|

楼主 |
发表于 18-7-2005 12:12 PM
|
显示全部楼层
谁有用过mysql的lock table这个程式??? |
|
|
|
|
|
|
| |
本周最热论坛帖子
|