简体   繁体   English

MySQL MyISAM-执行插入而不锁定

[英]MySQL MyISAM - Do inserts without locking

How do I do ALWAYS do inserts into MySQL MyISAM database without locking the table? 如何始终在不锁定表的情况下插入MySQL MyISAM数据库?

When I load a 100,000 records my other processes appear to be locked. 当我加载100,000条记录时,其他进程似乎已锁定。

Basically, can I force the use of concurrent_inserts=2 even if there are holes in the table so there is NO table locking during inserts? 基本上,即使表中有孔,所以在插入过程中也没有表锁定时,我是否可以强制使用currently_inserts = 2?

Can concurrent_inserts be set for the session dynamically? 是否可以动态设置会话的并发插入? see http://dev.mysql.com/doc/refman/5.0/en/concurrent-inserts.html 参见http://dev.mysql.com/doc/refman/5.0/en/concurrent-inserts.html

What other methods are there for non-locking inserts? 非锁定刀片还有哪些其他方法?
Will "insert delayed" prevent table locking during inserts? “插入延迟”会阻止插入过程中的表锁定吗? see http://dev.mysql.com/doc/refman/5.5/en/insert-delayed.html 参见http://dev.mysql.com/doc/refman/5.5/en/insert-delayed.html

If you perform your inserts in small batches, using INSERT DELAYED will let the clients selecting from the table basically get first priority so they don't block. 如果您以小批量方式执行插入,则使用INSERT DELAYED将使从表中选择的客户端基本上获得优先权,因此它们不会阻塞。 If you insert thousands of rows in one shot you will potentially lock the table for a while. 如果在一张照片中插入数千行,则可能会锁定表一段时间。 Another thing that can help speed the inserts is to temporarily tell the DB to skip unique checks. 可以帮助加快插入速度的另一件事是暂时告诉DB跳过唯一检查。 That will prevent the constant analysis of any unique keys, but won't prevent locking of the table. 这将阻止对任何唯一键的持续分析,但不会阻止表的锁定。 You must be certain that what you insert is unique. 您必须确定插入的内容是唯一的。

When doing many inserts, InnoDB is often a better choice because it will lock the row and not the table. 当进行多次插入时,InnoDB通常是更好的选择,因为它将锁定行而不是表。 Your inserts will take longer but your clients will see better concurrent performance. 您的插入内容将花费更长的时间,但是您的客户将看到更好的并发性能。

I have had the same issue. 我有同样的问题。 I tried to insert 2,500,000 records into a MyISAM table. 我试图将2,500,000条记录插入MyISAM表中。 It is an independent table, so the lock doesn't worried me. 它是一个独立的表,所以锁不让我担心。 But the insert process just frozen the whole database server. 但是插入过程只是冻结了整个数据库服务器。

So what I did: 所以我做了什么:

  • remove all the INDEX-es (add these at the end of the process) 删除所有INDEX-es(在过程结束时添加它们)
  • do 2500 rows per insert 每插入2500行
  • use INSERT DELAYED INTO 使用INSERT DELAYED INTO

That's it. 而已。

IIRC MyISAM locks tables whilst any insert happens .. Just re-read and confirmed that : 当任何插入发生时,IIRC MyISAM会锁定表..只要重新阅读并确认:

To achieve a very high lock speed, MySQL uses table locking (instead of page, row, or column locking) for all storage engines except InnoDB, BDB, and NDBCLUSTER 为了达到很高的锁定速度,MySQL对除InnoDB,BDB和NDBCLUSTER以外的所有存储引擎使用表锁定(而不是页面,行或列锁定)

Taken from : http://dev.mysql.com/doc/refman/5.0/en/table-locking.html 取自: http : //dev.mysql.com/doc/refman/5.0/en/table-locking.html

If you do know of any non-locking MyISAM inserts, please let me know - as it's a problem I face daily (I don't like InnoDB space consumption and speed) 如果您知道任何非锁定MyISAM插入,请告诉我-因为这是我每天都会遇到的问题(我不喜欢InnoDB的空间消耗和速度)

MySQL does support parallel insertion in same table for MyISAM tables. MySQL确实支持在MyISAM表的同一表中并行插入。

MyISAM 我的ISAM

MySQL uses table-level locking for MyISAM, MEMORY, and MERGE tables, allowing only one session to update those tables at a time, making them more suitable for read-only, read-mostly, or single-user applications. MySQL对MyISAM,MEMORY和MERGE表使用表级锁定,一次只允许一个会话更新这些表,从而使其更适合于只读,以只读为主的应用程序或单用户应用程序。

But, the above mentioned behavior of MyISAM tables can be altered by concurrent_insert system variable in order to achieve concurrent write. 但是,MyISAM表的上述行为可以通过parallel_insert系统变量进行更改,以实现并发写入。 You can set value for the property as 1 or 2 , depending upon your requirement. 您可以根据需要将属性的值设置为12 Refer link for details. 详情请参阅链接。

Hence, as a matter of fact, MySQL does support concurrent insert for InnoDB and MyISAM storage engine. 因此,事实上,MySQL确实支持InnoDB和MyISAM存储引擎的并发插入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM