1. Features:
The MyISAM storage engine is biased, the overhead is small, the lock block is added, there is no deadlock, the locking force is large, the probability of lock conflicts is high, and the concurrency is low.
2. Check whether to lock:, SHOW OPEN TABLES
lock command:, lock table 表名 read, 表名 write,......
release tableunlock tables
(1) Add read lock (partial read)
- Thread 1, add table read lock, thread 1 is readable, not writable; can not read other tables.
- Thread 2, can read the table, you can also read other tables, but modify the thread 1 and add the lock table will be blocked.
(2) Add write lock (partial write) - Thread 1, add a write lock, thread 1 can read the table it has locked, can modify the table it has locked, and cannot read other tables
- Thread 2, can check other tables, the table locked by reading thread 1 will be blocked until the table lock is released.
3. Summary
In short, read locks will block writes, but will not block reads, and write locks will block both reads and writes
4. Analysis of table lock
(1) SHOW OPEN TABLES
You can check which tables are locked
(2) You can analyze table locks on the system by checking table_locks_watied
and table_locks_immedinate
state variables:show status like 'table%';
table_locks_immedinate
Represents the number of table-level locks, the number of queries that can immediately obtain a lock, plus 1 for each immediate lock valuetable_locks_watied
The number of waits for table-level lock contention (the number of times the lock cannot be obtained immediately, plus 1 for each lock value). A high value indicates a serious table-level lock contention.
In addition, the MyISAM engine read and write scheduling is write priority, which is also not suitable for MyISAM to be written as the main table engine. Because after the lock is written, other threads cannot do any operation, and a large number of updates will make it difficult for the query to obtain the lock, thereby causing permanent blocking.