MySQL锁查询与锁释放实操

1. 查询一个数据表中可测试数据

SELECT * FROM t_wx_authorizer_info WHERE service_id = '30127' for update;

2. 实验制造数据库锁,以下语句都先只执行第一条更新语句,然后再执行第二条更新语句的时候就会锁住

-- 第一个事务,只执行第一条更新语句
start transaction;
update t_wx_authorizer_info set remarks = 'lock0' WHERE id = '36';
update t_wx_authorizer_info set remarks = 'lock0' WHERE id = '38';
commit;

-- 第二个事务,只执行第一条更新语句
start transaction;
update t_wx_authorizer_info set remarks = 'lock0' WHERE id = '36';
update t_wx_authorizer_info set remarks = 'lock0' WHERE id = '38';
commit;

3. 查询锁情况

-- 查询出锁的线程
select concat('KILL ',id,';'), p.*, x.*
from information_schema.processlist p 
inner join information_schema.INNODB_TRX x on p.id=x.trx_mysql_thread_id;

4. 关闭一个线程,释放锁

KILL 1189233;

查询

-- 当前运行的所有事务
SELECT * FROM information_schema.INNODB_TRX;
-- 查询当前出现的锁
SELECT * FROM information_schema.INNODB_LOCKs;
-- 锁等待的对应关系
SELECT * FROM information_schema.INNODB_LOCK_waits;

 

posted @ 2023-06-02 18:13  彩虹雨·洋  阅读(391)  评论(0编辑  收藏  举报