zoukankan      html  css  js  c++  java
  • mysql如何解除死锁状态

    第一种:

    前提条件:找到执行非常慢的sql;

    如何找呢:还原客户遇到的问题场景,从控制台找到所执行的sql,一句句的去执行,直到找到执行非常慢的sql

    1.查询是否锁表

    show OPEN TABLES where In_use > 0;

    2.查询进程(如果您有SUPER权限,您可以看到所有线程。否则,您只能看到您自己的线程)

    show processlist

    3.杀死进程id(就是上面命令的id列)

    kill id

    第二种:

    1.查看下在锁的事务 

    SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;

    2.杀死进程id(就是上面命令的trx_mysql_thread_id列)

    kill 线程ID

    第三种:

    也许你无法查看到所在的info,这个时候你需要重启服务器,如果是分布式的话,就一台台重启吧;

    原理是:杀死所有进程,释放所有锁。

    MySQL - 锁等待超时与information_schema的三个表:
    -- 1.information_schema.innodb_trx–当前运行的所有事务
    select * from information_schema.innodb_trx;

    -- information_schema.innodb_locks–当前出现的锁
    select * from information_schema.innodb_locks;

    -- information_schema.innodb_lock_waits–锁等待的对应关系
    select * from information_schema.innodb_lock_waits;
    -------------------------------------------------------------------------------------------
    //常用

    MySQL - 锁等待超时与information_schema的三个表:
    -- 1.information_schema.innodb_trx–当前运行的所有事务
    select * from information_schema.innodb_trx;

    -- information_schema.innodb_locks–当前出现的锁
    select * from information_schema.innodb_locks;

    -- information_schema.innodb_lock_waits–锁等待的对应关系
    select * from information_schema.innodb_lock_waits;
    -------------------------------------------------------------------------------------------
    //常用
    select * from information_schema.innodb_trx where trx_state = 'LOCK WAIT';

    SELECT a.* FROM information_schema.processlist a where command <> 'sleep' ORDER BY time desc

    select * from information_schema.processlist where time> 60 and user='srapp_stsj';

    SELECT
    concat('kill',' ', id,';')
    FROM
    information_schema. PROCESSLIST a
    WHERE
    command <> 'sleep'
    AND info LIKE 'select%'
    AND time > 60
    and user = 'srapp_stsj'
    ORDER BY
    time DESC

    EXPLAIN
    select * from sr_main where sys_scbj = '0' and mdjlx = 'ls_jz' and sys_spzt = 2
    and mhzsfz = '330219193210200010'

  • 相关阅读:
    restframework 使用OrderingFilter实现排序
    restframework 使用django_filters 实现过滤
    Serializer 嵌套使用
    docker 运行scrpyd
    flutter-lol云顶之弈助手app
    微信小程序上传多张图片,后端只保存了最后一张的Bug
    ettercap局域网arp欺骗,轻松窃密
    GoLang邮件发送Demo(继上篇msmtp)
    Mac下命令行发邮件【搭配php(shell_exec...)等脚本语言,轻松发邮件,告别各种依赖库】
    我的第一个RN应用(漂亮的首页和笑话列表)
  • 原文地址:https://www.cnblogs.com/tongcc/p/11807551.html
Copyright © 2011-2022 走看看