Get the App
SLTechnology News&Howtos  ›  Database  › 

How mysql modifies transaction isolation level

Shulou Source: shulou.com Published: 2022-05-31 15:51:04 09月11日 Update

Editor to share with you how to modify the transaction isolation level of mysql, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Users can use SET TRANSACTION statements to change the isolation level for a single session or for all new connections. Its syntax is as follows:

SET [SESSION | GLOBAL] TRANSACTION ISOLATION LEVEL {READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE}

Note: the default behavior (without session and global) is to set the isolation level for the next (not started) transaction. If you use the GLOBAL keyword, the statement sets the default transaction level globally for all new connections created from that point (except for those that do not exist). You need SUPER permission to do this. Use the SESSION keyword to set the default transaction level for future transactions executed on the current connection. Any client is free to change the session isolation level (even in the middle of the transaction) or set the isolation level for the next transaction. Mysql > set tx_isolation='read-committed'

Query OK, 0 rows affected (0.00 sec)

+-+

| | @ @ tx_isolation |

+-+

| | READ-COMMITTED |

+-+

1 row in set (0.00 sec)

Mysql > select @ @ session.tx_isolation

+-- +

| | @ @ session.tx_isolation |

+-- +

| | READ-COMMITTED |

+-- +

1 row in set (0.00 sec)

Transaction isolation has changed.

There are still people on the Internet who write the set @ @ tx_isolation command, but this command is problematic.

Mysql > set @ @ tx_isolation='read-committed'

Query OK, 0 rows affected (0.00 sec)

Mysql > select @ @ session.tx_isolation

+-- +

| | @ @ session.tx_isolation |

+-- +

| | REPEATABLE-READ |

+-- +

1 row in set (0.00 sec)

Mysql > select @ @ tx_isolation

+-+

| | @ @ tx_isolation |

+-+

| | REPEATABLE-READ |

+-+

1 row in set (0.00 sec)

The isolation level of session things has not changed.

These are all the contents of the article "how mysql modifies transaction isolation levels". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Transaction level isolation article key keyword content command statement freedom not so much thing global single most client client more permissions user Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Apple vpn NVidia