MySQL InnoDB row lock table lock

Source: Internet
Author: User

Today, we chatted with each other about the InnoDB engine. They asked me for a lot of things I don't know, but they even got the lock. I still know this, so I just said: if indexes are used in the MyISAM engine, row locks are applied and the obtained results are index tables. If indexes are not used, table locks are applied. I thought it was awesome, but I also asked how I knew it. I said I care about what I saw on the blog. Just now, I feel that it is not convincing. Then I said: I seem to have read it in the MySQL help document (but I have never seen it ). The boss said: The help document is not necessarily correct. The version may be modified if it is different. It is better to try it.

Indeed, I thought about what I learned, but it is estimated that 80% of them are from the Internet blog. Even official documents may have version problems and slight changes. Except for some code, I do not have time for this kind of knowledge. Buy it first and I will try it out for you.

First, you need to open two MySQL windows.

Create a table with two fields, one of which is set as index and the other is not:

Then add the data:

Now let's start things and update them to understand:

Then update in another window

But it's already deadlocked. We don't know what we can do in the first window of commit.

Then we try to update other options:

No problem, so it is a row lock, not a table lock. Then, we don't need to use ID for conditions.

It can be seen that this is a table lock without an index. Haha, although it is very simple, I would like to say: it is estimated that this is the first practical knowledge except code.

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.