Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does mysql lock tables on select, update or delete?

Tags:

mysql

locking

I have a few questions about MySQL table lock. I appreciate if anyone answers :)

  1. Does MySQL lock tables automatically in the following cases:

    • SELECT id FROM members;
    • UPDATE members SET name = 'john' WHERE id = 7;
  2. What is the difference between these two:

    • LOCK TABLE items READ ; SELECT * FROM 'items;
    • SELECT * FROM 'items';
  3. For some reason I was under the impression that MySQL automatically locks the tables on necessary occasions! How can I check when and how the locking happens?

Thank you.

like image 608
ben jaz Avatar asked Apr 16 '13 09:04

ben jaz


1 Answers

1.a) no lock required
1.b) locks the table (myisam engine) or you have row level locking if your using innodb engine

2.a) locks the table for read operations (until this lock is released no writing operations occur)
2.b) no lock required

As Lithu T.V suggested please read the DOCS to get the all the use cases.

like image 96
Stephan Avatar answered Oct 17 '22 08:10

Stephan