我在 AWS 上使用 innoDB。我的日志中不断收到大量以下消息:
等待表级锁
我以为 innoDB 只做行级锁。我的代码中没有任何锁表。有谁知道为什么会发生这种情况?
我在 AWS 上使用 innoDB。我的日志中不断收到大量以下消息:
等待表级锁
我以为 innoDB 只做行级锁。我的代码中没有任何锁表。有谁知道为什么会发生这种情况?
There are certain reasons when InnoDB table locks comes into picture:
1) InnoDB is aware of table locks if innodb_table_locks = 1
(the default) and autocommit = 0
, and the MySQL layer above InnoDB knows about row-level locks.
You should set innodb_table_locks=0
and restart MySQL server.
2) While initializing a previously specified AUTO_INCREMENT
column on a table, InnoDB sets an exclusive lock on the end of the index associated with the AUTO_INCREMENT column. While accessing the auto-increment counter, InnoDB uses a specific AUTO-INC
table lock mode where the lock lasts only to the end of the current SQL statement, not to the end of the entire transaction. Other clients cannot insert into the table while the AUTO-INC
table lock is held.
You can refer this blog post as well: http://www.mysqlperformanceblog.com/2012/07/31/innodb-table-locks/
在某些情况下,innoDB 会做表锁(如 AUTO-INC),请参阅这篇文章,看看是否适用于您的情况:InnoDB 表锁
innodb_table_locks=0
还要检查是否在 MySQL 配置中设置或设置 。请参阅此处获取文档: InnoDB 启动选项和系统变量