Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql concurrency: what happens if a locked table is accessed?

The question is rather simple but I couldn't find a precise answer: In a myisam db, what happens if a php file locks a table (with an atomic operation, say an INSERT) and another php file tries to access the same table (reading or writing)?

Now, while it is obvious that the second session will not be able to access the table, what exactly happens? Does it return some kind of error? Does it wait in queue until it is able to access it?

like image 958
PixelSapiens Avatar asked Mar 20 '12 11:03

PixelSapiens


1 Answers

The second connection will wait for the lock to free.

With MyISAM any write (insert / update / delete) will lock the table,

However with INNODB table type the atomic operation will only lock the affected rows

like image 62
Mark Willis Avatar answered Nov 17 '22 12:11

Mark Willis