InnoDB 設計上允許同時讀寫,在大多數的情況下不會產生 table lock,不過還是有機會。(或是刻意產生)
在「Innodb Table Locks」這篇文章提到 InnoDB 的各種 lock (都是帶過而已,不過當關鍵字去 Google 找應該是夠用了),在文章最後面整理出結論,第一個是:
MySQL Table level locks and Innodb Table Level locks are two separate beings.
而就算是 InnoDB,你也還是可以用 LOCK TABLES
,效果的確會如同你想的,只是這並不是由 InnoDB engine 實作。而最後是這樣建議:
It is a good practice not to use LOCK TABLES when you're using Innodb Tables.
另外註解也有提到 auto inc primary key 偶而也會造成問題,都可以當關鍵字去找出細節 :p
Reply to「長野雅廣 (Masahiro Nagano) 的 MySQL Beginners Talk」的 comment :p