开发者

Lock innoDB table temporarily

开发者 https://www.devze.com 2022-12-30 01:45 出处:网络
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 insert开发者_开发知识库s hav

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 insert开发者_开发知识库s have been done.

What is the best way to do this while keeping the read availability open for normal, non-admin users?

Thanks!


You may also need to change default isolation level:

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


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.


Why not just do the insert in one big transaction? That would kind of prevent the need for any locking.

0

精彩评论

暂无评论...
验证码 换一张
取 消