tags:

views:

568

answers:

2

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?

A: 

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

Kamia
He's using MyISAM, which is not transactional. So this won't work at all.
derobert
+1  A: 

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

derobert
an insert of a new record on myisam (to the end of the table) does not lock the entire table.
Omry
Yes, it does, if there are no holes in the data file (e.g., no deletes since the last optimize). http://dev.mysql.com/doc/refman/5.0/en/concurrent-inserts.html describes the behavior in detail.
derobert