Michael
Michael

Reputation: 1866

MySQL InnoDB Transactions + Locking

MySQL Verion: v5.0.95

Basically I have clients trying to get data - each client should only get unique rows.

START TRANSACTION;

SELECT id where result='new';

UPDATE SET result='old' WHERE id=$id;

COMMIT;

LOCK IN SHARED MODE on the select statement still lets other clients read the data, which seems like a problem.

Basically I need the data selected once, updated, and not read again by another client.

Upvotes: 2

Views: 791

Answers (1)

Maxim Krizhanovsky
Maxim Krizhanovsky

Reputation: 26699

SELECT FOR UPDATE will block another read, while LOCK IN SHARED MODE will allow the read, but won't allow update from another client

Upvotes: 5

Related Questions