是否可以在 mysql 中发出选择查询而不采取任何读锁?
看来mysql选择内容(而不是例如计数)查询总是至少在myisam表上获取表读锁,并在innodb表上获取行读锁。有没有办法在 mysql 中发出选择内容查询(如果需要,我可以更改表类型)而不让它抓住任何锁?我不介意返回的数据是否不一致,因为我将使用它作为搜索索引。
It seems that mysql select content (as opposed to e.g. count) queries always take at least a table read lock on myisam tables and a row read lock on innodb tables. Is there a way to issue a select content query in mysql (I could change table type if that's required) without having it to grab any locks? I don't mind if the data returned is inconsistent since I will use it for a search index.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用InnoDB,您可以通过将事务隔离级别设置为:
未提交的内容
。在此隔离级别下:
您可以从 MySQL 选项文件更改默认事务隔离级别,或者可以为单个会话启用和禁用它:
进一步阅读:MySQL 文档:设置事务
With InnoDB you achieve this by setting the transaction isolation level to:
READ UNCOMMITTED
.In this isolation level:
You can either change the default transaction isolation level from the MySQL option file, or else it can be enabled and disabled for a single session:
Further Reading: MySQL Documentation: Set Transaction
在没有LOCK TABLES的情况下,myisam应该相当于读未提交模式,但它实际上不支持任何事务类型...
innodb默认运行在“一致读”模式(处于“可重复读”隔离级别),这文档建议不会锁定:
http://dev.mysql.com/doc/ refman/5.0/en/innodb-consistent-read.html
in the absence of LOCK TABLES, myisam should be equivalent to read uncommitted mode, but it doesn't actually support any transaction types...
innodb runs in "consistent read" mode (at "repeatable read" isolation level) by default, which the docs suggest won't lock:
http://dev.mysql.com/doc/refman/5.0/en/innodb-consistent-read.html