MySQL table-Level Lock

Source: Internet
Author: User

MyISAM uses table-level locks by default. Generally, table-level locks in Web applications can meet the requirements. InnoDB uses row-level locks by default, but it also supports table-level locks. Row-level locks are more accurate and consume the most resources. The Berkeley DB Engine uses page-level locks by default, each of which has its own merits.
1. MySQL table-Level Lock usage:
Lock table [tablename] [lock-type];
For example, add a read lock to table test1:
Lock table test1 read;
2. How to unlock MYSQL:
Unlock tables;
The preceding method uses table-level and release. The following conclusions can be tested in person, which is also obtained from my tests:
1. Write locks take precedence over read locks (this can be set using parameters );
2. When a read lock occurs, the write lock cannot be added, but the read lock can be applied;
3. When there is a write lock, neither the read lock nor the write lock can be added;
When a conflict occurs, the latter is added to the blocking queue.
OK. The above conclusion can be verified using the lock usage method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.