在我的 php 页面中
LOCK TABLE invoice_numbers WRITE
/*some stuff */
SELECT * FROM link_master
/*some stuff */
UNLOCK TABLES
我的问题是在锁定表 invoice_numbers 之后。我无法访问link_master 表,但解锁后我可以访问link_master 表
为什么会这样?锁定 invoice_numbers 表后如何访问 link_master?
编辑:
我只想锁定单个表 invoice_numbers。在锁定期间,我想使用数据库中的所有其他表。有什么办法吗?
最佳答案
A session that requires locks must acquire all the locks that it needs in a single LOCK TABLES statement. For example, in the following sequence of statements, an error occurs for the attempt to access t2 because it was not locked in the LOCK TABLES statement:
mysql> LOCK TABLES t1 READ; mysql> SELECT COUNT(<em>) FROM t1; +----------+ | COUNT(</em>) | +----------+ | 3 | +----------+ mysql> SELECT COUNT(*) FROM t2; ERROR 1100 (HY000): Table 't2' was not locked with LOCK TABLES
关于php - Mysql表锁定问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4584700/