Skip to main content
 首页 » 数据库

mysql 隔离级别,事务测试

2022年07月18日176mate10pro

基础:


# 查询mysql的版本
select version();

# 查询事务的隔离级别
select @@tx_isolation;

SELECT @@transaction_isolation;


set session tx_isolation='REPEATABLE-READ';

set session tx_isolation='read-committed';

# 设置全局的事务隔离级别 spring默认的隔离级别是指mysql设置的隔离级别(spring的值为 default 或 -1)
set global transaction_isolation ='read-committed';


show global variables like '%isolation%';


# 查询日志path
show VARIABLES like 'log_%';

# 查询事务
SELECT * FROM information_schema.INNODB_TRX;

# 查询超时时间
SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';

#设置超时时间
SET innodb_lock_wait_timeout=6;

# 查询最后一次死锁的日志
show engine innodb status

A客户端:

select version();
select @@autocommit;
set session autocommit = 0;

set session tx_isolation='REPEATABLE-READ';
set session tx_isolation='SERIALIZABLE';

START TRANSACTION;

SELECT * from cloudwalk_auth ;

COMMIT;

select @@tx_isolation;

B 客户端:

select @@autocommit;
set session autocommit = 0;

set session tx_isolation='REPEATABLE-READ';
set session tx_isolation='SERIALIZABLE';

start TRANSACTION;

UPDATE cloudwalk_auth set branch_id=-1;

SELECT * from cloudwalk_auth;
COMMIT;

select @@tx_isolation;


本文参考链接:https://www.cnblogs.com/maohuidong/p/14629092.html