简体   繁体   English

临时锁定innoDB表

[英]Lock innoDB table temporarily

I make bigger inserts consisting of a couple of thousand rows in my current web app and I would like to make sure that no one can do anything but read the table, until the inserts have been done. 我在当前的Web应用程序中制作了包含两千行的较大的插入,并且我想确保在插入完成之前,除了读取表以外,其他任何人都无法做。

What is the best way to do this while keeping the read availability open for normal, non-admin users? 在保持正常的非管理员用户可读性的同时,做到这一点的最佳方法是什么?

Thanks! 谢谢!

Since you're only inserting (not updating) this shouldn't be a problem. 由于您仅插入(而不更新),因此这不是问题。 Just insert the records in a single transaction. 只需将记录插入单个事务中。

InnoDB supports row level locking if I recall correctly so even updates shouldn't be a problem. 如果我没记错的话,InnoDB支持行级锁定,因此即使更新也不成问题。

You may also need to change default isolation level: 您可能还需要更改默认隔离级别:

 set transaction isolation level serializable;
 start transaction;
 // insert data
 commit

Why not just do the insert in one big transaction? 为什么不只在一次大交易中插入? That would kind of prevent the need for any locking. 这样可以避免进行任何锁定。

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

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