在表上执行 SELECT 时我是否锁定表?
这是一个由两部分组成的问题。当我对表执行 SELECT 时,我是否会在 SELECT 运行期间锁定该表以防止任何使用?
如果是这样,有什么方法可以在执行 SELECT 语句时不锁定表?我正在使用 MySQL 4.1.20 MyISAM。
更新这里有一个类似的问题有什么方法可以在不导致 MySQL 锁定的情况下进行选择? 但答案不适用于 MyISAM
This is a two part question. When I perform a SELECT on a table, am I locking that table from any usage while the SELECT is running?
If so, what is a way to not lock the table while performing a SELECT statement? I'm using MySQL 4.1.20 MyISAM.
update there is a similar question here Any way to select without causing locking in MySQL? but the answer doesn't work with MyISAM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,对于 MyISAM 表,选择会锁定表以进行插入/更新。然而,多个选择可以同时运行(即它应用读锁)。如果表中间没有可用空间,则插入会将数据添加到(内部)存储的末尾,并且这些插入仍然可以与选择同时运行。
更多信息此处。请注意,MyISAM 和 InnoDB 在这方面的工作方式非常不同。
Yes, with MyISAM tables, the select locks the table for inserts/updates. However several selects can run concurrently (i.e. it applies a read lock). If there's no free space in the middle of the table, inserts will add data to the end of the (internal) storage, and those inserts can still be run concurrently with the selects though.
More info here. Note that MyISAM and InnoDB works very differently in this regard.
有表锁定和行锁定。我建议您阅读数据库引擎MyISAM with Table Locking 和 InnoDB 行锁定
There's table locking and row locking. I recommend you read up on database engines MyISAM with Table Locking and InnoDB Row Locking
想一想:当您执行 SELECT 操作时,您是否更改了任何表格单元格?如果没有,则无需锁定表,MySQL 也不会。表锁定必须发生在 UPDATE 时间,而不是 SELECT 时间。
Think about it: are you changing any table cells when you do your SELECT? If not, there's no need to lock the table and MySQL doesn't. Table locking has to happen at UPDATE time, not at SELECT time.