In MySQL (notably 5.5), it seems that we have two different methods to set the transaction isolation level. I just would like to know if I am right in thinking that
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
does exactly the same as
SET tx_isolation = 'REPEATABLE-READ'
and that this is true for the other possible isolation levels as well.
EDIT 1
I have not been precise enough. @danihp's answer is correct given my question. But actually, I intended to ask about
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ
versus
SET SESSION tx_isolation = 'REPEATABLE-READ'
(note the SET SESSION
instead of SET
).
Are they exactly the same?
Server system variables:
You can use SET tx_isolation = 'REPEATABLE-READ'
to set default isolation level on server system variables. "The MySQL server maintains many system variables that indicate how it is configured" This variable sets the default transaction level.
Current transaction:
You can use SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
to change isolation level from default to new level on your current transaction.
Notice:
"transaction_isolation
was added in MySQL 5.7.20 as an alias for tx_isolation
, which is now deprecated and is removed in MySQL 8.0. Applications should be adjusted to use transaction_isolation
in preference to tx_isolation
."
References:
Edited
You can use transactions to "encapsulate" several statements as a single operation. When you start a transaction, just at this time, you can change isolation level for this new transaction:
START TRANSACTION;
/** change isolation level here with SET TRANSACTION statement
to avoid default isolation level **/
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With