MySQL Query lock table

Source: Internet
Author: User
Tags mysql query

1) Using the scenario "to write to the database after the decision", this is generally not a problem, but the concurrent access is not very good. Because the write (insert) takes time, assume that there are now two concurrent requests, (assuming that the first access is the last qualifying write request, according to logic, the second request should be illegal, cannot be written), and the second request queries to the data record that was not updated before the first request was successfully written. Because the record is not updated, it can also be judged. Finally, two requests are written to the data.

2) Workaround: Query the Lock table

Before I finish handling the storage, I will not let you check, so you can not judge the wrong?

3) Lock Table statement

LOCK TABLES tbl_name WRITE;

Note that this is a write!!.

Unlock:

UNLOCK TABLES;

Note: to query before the lock table (select), after the lock table, the process is able to continue querying, just lock the query of other processes

MySQL Query lock table

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.