mysql sql优化相关[更新中]

1.慢sql查询。

select * from information_schema.processlist where command not in ('Sleep')  and user not in ('mydba','event_scheduler','repl','binlogbak','system user')

可以直接kill响应的id

2.死锁排查

查看当前正在进行中的进程

show processlist;
-- 或者
SELECT * FROM information_schema.INNODB_TRX;

然后kill掉相应的id

验证是否还有锁

SHOW OPEN TABLES where In_use > 0;

3.一些锁的语句

    1、查看正在进行中的事务
SELECT * FROM information_schema.INNODB_TRX
    2、查看正在锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
    3、查看等待锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
    4、查询是否锁表
SHOW OPEN TABLES where In_use > 0;
在发生死锁时,这几种方式都可以查询到和当前死锁相关的信息。
    5、查看最近死锁的日志
show engine innodb status

 

posted @ 2022-10-18 11:43  SpringCore  阅读(22)  评论(0编辑  收藏  举报