设置 MySQL 的事务隔离级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7937472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting transaction isolation level of MySQL
提问by Wen Jun
How do I set the isolation level of MySQL 5.1 InnoDB?
如何设置 MySQL 5.1 InnoDB 的隔离级别?
By entering:
通过输入:
mysql> show variables like '%isola%';
mysql> 显示变量如 '%isola%';
The default level set for InnoDB is repeatable read.
How do I change the isolation level?
InnoDB 的默认级别设置是可重复读取。
如何更改隔离级别?
回答by Niet the Dark Absol
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.
SESSION
是可选的,只是将设置限制为当前会话。READ UNCOMMITTED
将替换为您想要的级别。
回答by Sorter
Add session variable to connection string
将会话变量添加到连接字符串
Simply add it to the connection string, when connecting to the mysql database.
连接到mysql数据库时,只需将其添加到连接字符串中即可。
?sessionVariables=transaction_isolation='READ-COMMITTED'
?sessionVariables=transaction_isolation='READ-COMMITTED'
You can check for the values of other isolation levels.
您可以检查其他隔离级别的值。
回答by atrichkov
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:
我的默认隔离级别也是 REPEATABLE READ 上面的示例,您可以为当前会话更改它,但如果您想完全更改它,您可以尝试使用以下命令:
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Tested on Mysql server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)
在 Mysql 服务器版本上测试:5.7.23-0ubuntu0.18.04.1 (Ubuntu)