1

According to the MySQL documentation, if any session holds a Read lock for a table, then another session requests a Write lock for the same table, the Write lock must be given and the Read lock waits.

I tried it, connected to the MySQL server from two consoles (Windows 7). Locked the table A from the first console (read lock), then tried to lock the same table from the second console (write lock), but the second console just waits till the first lock releases.

Who is wrong: me or the documentation? (MySQL Server version 5.5.27)

The citation from the MySQL official documentation:

"WRITE locks normally have higher priority than READ locks to ensure that updates are processed as soon as possible. This means that if one session obtains a READ lock and then another session requests a WRITE lock, subsequent READ lock requests wait until the session that requested the WRITE lock has obtained the lock and released it."

4

2 回答 2

0

关键字是后续subsequent READ lock requests。我认为这是说现有的 READ 锁不会被暂停,而是会延迟在 WRITE 锁生效时发生的 READ 锁。所以我认为文档是正确的。

于 2012-08-29T21:41:06.417 回答
0

那里写着:

这意味着如果一个会话获得了 READ 锁,然后另一个会话请求了 WRITE 锁,则后续的READ 锁请求将等待,直到请求 WRITE 锁的会话获得并释放锁。

已经获得的 READ 锁不会在操作中被破坏。那会造成破坏。等待的是后续请求

于 2012-08-29T21:41:18.577 回答