如何设置事务隔离级别(MySQL)

发布于 2024-12-12 17:40:32 字数 159 浏览 1 评论 0原文

如何设置MySQL 5.1 InnoDB的隔离级别?

通过输入:

mysql>显示像 '%isola%' 这样的变量;

InnoDB 的默认级别设置是可重复读取。
如何更改隔离级别?

How do I set the isolation level of MySQL 5.1 InnoDB?

By entering:

mysql> show variables like '%isola%';

The default level set for InnoDB is repeatable read.
How do I change the isolation level?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初相遇 2024-12-19 17:40:32
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SESSION 是可选的,仅将设置限制为当前会话。
READ UNCOMMITTED 将替换为您想要的级别。

https://dev.mysql.com/doc/refman/8.0 /en/set-transaction.html

SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SESSION is optional, just limits the setting to the current session.
READ UNCOMMITTED is to be replaced with your desired level.

https://dev.mysql.com/doc/refman/8.0/en/set-transaction.html

爱已欠费 2024-12-19 17:40:32

您可以设置 4 个事务隔离级别和 4 个范围,如下所示。 *文档解释了如何设置事务隔离级别更详细地我的回答解释了如何显示 MySQL 中的事务隔离级别:

PERSIST 范围内,即使重新启动 MySQL 后,事务隔离级别也不会重置:

SET PERSIST TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

或:

SET PERSIST transaction_isolation = 'READ-UNCOMMITTED';

或:

SET @@PERSIST.transaction_isolation = 'READ-UNCOMMITTED';

GLOBAL 范围内,事务隔离级别在重启后重置重新启动 MySQL:

SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;

或:

SET GLOBAL transaction_isolation = 'READ-COMMITTED';

或:

SET @@GLOBAL.transaction_isolation = 'READ-COMMITTED';

使用 SESSION 作用域,注销 MySQL 后重置事务隔离级别:

SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;

或:

SET SESSION transaction_isolation = 'REPEATABLE-READ';

或:

SET @@SESSION.transaction_isolation = 'REPEATABLE-READ';

或:

SET transaction_isolation = 'REPEATABLE-READ';

不使用作用域,在执行下一个事务后重置事务隔离级别:

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

或者:

SET @@transaction_isolation = SERIALIZABLE;

You can set 4 transaction isolation levels with 4 scopes as shown below. *The doc explains how to set transaction isolation level in more detail and my answer explains how to show transaction isolation level in MySQL:

With PERSIST scope, transaction isolation level is not reset even after restarting MySQL:

SET PERSIST TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

Or:

SET PERSIST transaction_isolation = 'READ-UNCOMMITTED';

Or:

SET @@PERSIST.transaction_isolation = 'READ-UNCOMMITTED';

With GLOBAL scope, transaction isolation level is reset after restarting MySQL:

SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;

Or:

SET GLOBAL transaction_isolation = 'READ-COMMITTED';

Or:

SET @@GLOBAL.transaction_isolation = 'READ-COMMITTED';

With SESSION scope, transaction isolation level is reset after logging out of MySQL:

SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;

Or:

SET SESSION transaction_isolation = 'REPEATABLE-READ';

Or:

SET @@SESSION.transaction_isolation = 'REPEATABLE-READ';

Or:

SET transaction_isolation = 'REPEATABLE-READ';

With no scope, transaction isolation level is reset after performing the next single transaction:

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

Or:

SET @@transaction_isolation = SERIALIZABLE;
憧憬巴黎街头的黎明 2024-12-19 17:40:32

将会话变量添加到连接字符串

当连接到 mysql 数据库时,只需将其添加到连接字符串即可。

?sessionVariables=transaction_isolation='READ-COMMITTED'

您可以检查其他隔离级别的值。

Add session variable to connection string

Simply add it to the connection string, when connecting to the mysql database.

?sessionVariables=transaction_isolation='READ-COMMITTED'

You can check for the values of other isolation levels.

黑寡妇 2024-12-19 17:40:32

我的默认隔离级别也是 REPEATABLE READ,在上面的示例中,您可以为当前会话更改它,但如果您想完全更改它,您可以尝试使用以下命令:

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;

在 Mysql 服务器版本上测试:5.7.23-0ubuntu0.18.04.1 (乌班图)

My default isolation level is also was REPEATABLE READ with the example above you can change it for current session but if you want to change it entirely you can try with this command:

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;

Tested on Mysql server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文