23

如何确定给定查询使用的隔离级别?执行查询后(由第 3 方应用程序),我想知道使用了哪个隔离级别(例如,未提交的读取)。

需要明确的是,我目前正在开发一个使用 EF4 对 mysql 5.1 运行的应用程序。我正在尝试测试不同的编码模式以更改特定 EF4 查询的隔离级别。我需要能够测试并确保隔离级别设置正确。

4

1 回答 1

36
SHOW VARIABLES LIKE 'tx_isolation';

或者如果你有 MySQL 5.1+

SELECT * FROM information_schema.session_variables
WHERE variable_name = 'tx_isolation';

如果你想知道服务器全局配置了什么,把上面的改成如下:

SHOW GLOBAL VARIABLES LIKE 'tx_isolation';

或者如果你有 MySQL 5.1+

SELECT * FROM information_schema.global_variables
WHERE variable_name = 'tx_isolation';

如果您想让查询显示正在使用的事务隔离,请运行以下命令:

SELECT variable_value IsolationLevel
FROM information_schema.session_variables
WHERE variable_name = 'tx_isolation';

免责声明:我不知道 EF4

If you are allowed to embed subqueries in the SQL about to be run by EF4, you may have to embed this query as a subquery (or embed you query as a subquery) and display the variable IsolationLevel along with the results of the actual query.

于 2011-03-18T03:15:12.227 回答