Question

I have read many times that MySQL will perform table level locks on MyISAM tables during inserts. It's OK with me if that lock is ment for serializing insert/delete commands only. Inserts are very infrequent on my website any way.

But will that lock block all Select queries too until the insert command finishes?

Was it helpful?

Solution

A write lock will block all selects that use the tables you've locked.

OTHER TIPS

To accomplish isolation levels in MySQL server you can change the session isolation mode using SET SESSION command.

SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
SELECT * FROM TABLE_NAME ;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ ;

The above statement will work like WITH (nolock) i.e READ UNCOMMITTED data. You can also set the isolation level globally for all connections.

SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;

There are two system variables related to isolation level in MySQL server.

SELECT @@global.tx_isolation;
SELECT @@tx_isolation;

The first statement will return the global isolation level, the second will return only for current session.

In SQL Server you can also set the isolation level at transaction level like this.

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
GO

reade more @: mysql with nolock

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top