美文网首页
事务查看

事务查看

作者: 不排版 | 来源:发表于2018-03-21 11:10 被阅读13次

一些查看数据库中事务和锁情况的常用语句
查询 正在执行的事务:
SELECT * FROM information_schema.INNODB_TRX
根据这个事务的线程ID(trx_mysql_thread_id):
查看事务等待状况:
SELECT
r.trx_id waiting_trx_id,
r.trx_mysql_thread_id waiting_thread,
r.trx_query waiting_query,
b.trx_id blocking_trx_id,
b.trx_mysql_thread_id blocking_thread,
b.trx_query blocking_query
FROM
information_schema.innodb_lock_waits w
INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;
● 1
● 2
● 3
● 4
● 5
● 6
● 7
● 8
● 9
● 10
● 11
查看更具体的事务等待状况:
SELECT
b.trx_state,
e.state,
e.time,
d.state AS block_state,
d.time AS block_time,
a.requesting_trx_id,
a.requested_lock_id,
b.trx_query,
b.trx_mysql_thread_id,
a.blocking_trx_id,
a.blocking_lock_id,
c.trx_query AS block_trx_query,
c.trx_mysql_thread_id AS block_trx_mysql_tread_id
FROM
information_schema.INNODB_LOCK_WAITS a
LEFT JOIN information_schema.INNODB_TRX b ON a.requesting_trx_id = b.trx_id
LEFT JOIN information_schema.INNODB_TRX c ON a.blocking_trx_id = c.trx_id
LEFT JOIN information_schema.PROCESSLIST d ON c.trx_mysql_thread_id = d.id
LEFT JOIN information_schema.PROCESSLIST e ON b.trx_mysql_thread_id = e.id
ORDER BY
a.requesting_trx_id;
● 1
● 2
● 3
● 4
● 5
● 6
● 7
● 8
● 9
● 10
● 11
● 12
● 13
● 14
● 15
● 16
● 17
● 18
● 19
● 20
● 21
● 22
查看未关闭的事务:
–MySQL 5.6
SELECT
a.trx_id,
a.trx_state,
a.trx_started,
a.trx_query,
b.ID,
b.USER,
b.DB,
b.COMMAND,
b.TIME,
b.STATE,
b.INFO,
c.PROCESSLIST_USER,
c.PROCESSLIST_HOST,
c.PROCESSLIST_DB,
d.SQL_TEXT
FROM
information_schema.INNODB_TRX a
LEFT JOIN information_schema.PROCESSLIST b ON a.trx_mysql_thread_id = b.id
AND b.COMMAND = 'Sleep'
LEFT JOIN PERFORMANCE_SCHEMA.threads c ON b.id = c.PROCESSLIST_ID
LEFT JOIN PERFORMANCE_SCHEMA.events_statements_current d ON d.THREAD_ID = c.THREAD_ID;
● 1
● 2
● 3
● 4
● 5
● 6
● 7
● 8
● 9
● 10
● 11
● 12
● 13
● 14
● 15
● 16
● 17
● 18
● 19
● 20
● 21
● 22
–MySQL 5.5
SELECT
a.trx_id,
a.trx_state,
a.trx_started,
a.trx_query,
b.ID,
b. USER,
b. HOST,
b.DB,
b.COMMAND,
b.TIME,
b.STATE,
b.INFO
FROM
information_schema.INNODB_TRX a
LEFT JOIN information_schema.PROCESSLIST b ON a.trx_mysql_thread_id = b.id
WHERE
b.COMMAND = 'Sleep';
● 1
● 2
● 3
● 4
● 5
● 6
● 7
● 8
● 9
● 10
● 11
● 12
● 13
● 14
● 15
● 16
● 17
● 18
查看某段时间以来未关闭事务:
SELECT
trx_id,
trx_started,
trx_mysql_thread_id
FROM
INFORMATION_SCHEMA.INNODB_TRX
WHERE
trx_started < date_sub(now(), INTERVAL 1 MINUTE)
AND trx_operation_state IS NULL
AND trx_query IS NULL;

相关文章

  • 事务查看

    一些查看数据库中事务和锁情况的常用语句查询 正在执行的事务:SELECT * FROM information_s...

  • 黑猴子的家:mysql 事物实操

    1、事务总结 2、查看事务是否自动开启 3、事务案例演示一 4、演示delete和truncate在事务中的区别 ...

  • mysql常用命令

    lock 查看事务隔离级别 select @@transaction_isolation; 设置全局事务(影响新的...

  • mysql笔记

    mysql笔记 查看事务隔离级别 show variables like '%iso%'; 设置事务级别 mysq...

  • Mysql事务控制语句

    介绍 Mysql的Innodb存储引擎默认事务都是自动提交(隐式提交);查看当前的事务是否自动提交: 事务操作 开...

  • MySQL事务处理二

    SELECT @@AUTOCOMMIT; 查看MySQL是否自动提交事务 0表示手动提交事务 1表示自动提交事...

  • 基于JQuery实现的todolist(1)

    前言 利用 jQuery 实现的PC端事务管理应用,能够对事务进行增删改,查看事务的详情信息,标记完成事务以及实现...

  • mysql数据库锁

    mysql开启事务的三种方式(查看事务是否自动提交)show variables LIKE 'autocommit...

  • 事务隔离级别

    以mysql为例,查看当前事务隔离级别

  • 分布式事务及seata简单了解

    事务的acid,隔离级别这里不说了可以查看数据库事务的隔离级别及常见事务异常 - 简书 (jianshu.com)...

网友评论

      本文标题:事务查看

      本文链接:https://www.haomeiwen.com/subject/irbwqftx.html