美文网首页MySQL(总)
日常SQL(自用)

日常SQL(自用)

作者: 飞翔的Tallgeese | 来源:发表于2019-03-29 16:58 被阅读3次

#查询当前正在执行的语句

select user 用户,substring(host,1,instr(host,':')-1) IP,substring(host,instr(host,':')+1) 端口,time 执行时间,info 执行语句 from information_schema.processlist where command='Query';

#查询锁等待的相关信息

查询出的结果按阻碍次数排名,排名最高的那个阻碍事务ID就是这一串锁的源头(但这个ID对应的语句通常已经是sleep状态了,不会在processlist语句里面显示出来)

select c.*,b.pm 阻碍次数排名 from

(

select a.阻碍事务ID,count(a.阻碍事务ID) pm from

(

select  p.user 用户,

substring(p.host,1,instr(p.host,':')-1) IP,

substring(p.host,instr(p.host,':')+1) 端口,

p.id 进程ID,

t.trx_id 被阻事务ID,

lw.blocking_trx_id 阻碍事务ID,

concat(if(lw.blocking_trx_id is not null,lw.blocking_trx_id,'未产生'),'阻碍',if(t.trx_id is not null,t.trx_id,'')) 阻碍情况,

p.time 等待时间,

p.info 当前进程号对应的被阻语句

from information_schema.processlist p

left join information_schema.INNODB_TRX t

on p.id=t.trx_mysql_thread_id

left join information_schema.INNODB_lock_waits lw

on t.trx_id=lw.requesting_trx_id

where command='Query'

) a

group by a.阻碍事务ID

) b,

(

select  p.user 用户,

substring(p.host,1,instr(p.host,':')-1) IP,

substring(p.host,instr(p.host,':')+1) 端口,

p.id 进程ID,

lw.blocking_trx_id 阻碍事务ID,

t.trx_id 被阻事务ID,

concat(if(lw.blocking_trx_id is not null,lw.blocking_trx_id,'未产生'),'阻碍',if(t.trx_id is not null,t.trx_id,'')) 阻碍情况,

p.time 等待时间,

p.info 当前进程号对应的被阻语句

from information_schema.processlist p

left join information_schema.INNODB_TRX t

on p.id=t.trx_mysql_thread_id

left join information_schema.INNODB_lock_waits lw

on t.trx_id=lw.requesting_trx_id

where command='Query'

) c

where b.阻碍事务ID=c.阻碍事务ID

order by b.pm desc;

相关文章

  • 日常SQL(自用)

    #查询当前正在执行的语句 select user 用户,substring(host,1,instr(host,'...

  • SQL常用函数(自用)

    扩展: SQL中常用的函数, 这些函数 与 Hive中的函数, 80%以上, 都是一样的, 现在掌握了, 学Hiv...

  • 日常Ios开发常用的技巧

    日常Ios开发常用的技巧 自用 不断完善中... 1、禁止手机睡眠 [UIApplication sharedAp...

  • 如何成为写SQL高手(上)

    标准结构化查询语言(Structured Query Language)简称SQL,sql是我们日常工作中使...

  • [SQL]PostgreSQL日常维护SQL

    --查看数据库 select * from pg_database; --查看表空间 select * from ...

  • MySQL中,21个写SQL的好习惯

    1. 写完SQL先explain查看执行计划(SQL性能优化) 日常开发写SQL的时候,尽量养成这个好习惯呀:写完...

  • sql日常使用

    删除表数据,标识列Id从1开始TRUNCATE TABLE TbName --TbName是表名

  • sql命令日常

    ①学生表:Student由学号(Sno)、姓名(Sname)、性别(Ssex)、年龄(Sage)、所在系(Sdep...

  • MySQL Explain

    mysql执行计划 在日常工作中,为了知道优化SQL语句的执行,需要查看SQL语句的具体执行过程,以加快SQL语句...

  • mybatis如何预防不经意间的SQL注入

    SQL注入的危害就不多说,但是如何在日常开发中预防SQL注入? 1. 理论 什么是SQL注入 注入攻击的本质,是程...

网友评论

    本文标题:日常SQL(自用)

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