简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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