“ mysql 问题排查基本方法 ”

发布时间:2025-01-22
今日阅读:0
来源:rqsay
作者:RQSay
...

排查

查询是否锁表

show open tables where in_use > 0;  

查询进程

show processlist;

查询再锁的事务

select * from information_schema.innodb_locks;

查询等待锁的事务

select * from information_schema.innodb_lock_waits;

杀掉进程

kill {进程号}

查询死锁详情

select r.trx_id                                                    waiting_trx_id,
       r.trx_mysql_thread_id                                       waiting_thread,
       timestampadd(second, r.trx_wait_started, current_timestamp) wait_time,
       r.trx_query                                                 waiting_query,
       l.lock_table                                                waiting_table_lock,
       b.trx_id                                                    blocking_trx_id,
       b.trx_mysql_thread_id                                       blocking_thread,
       substring(p.`host`, 1, instr(p.`host`, ':') - 1)            blocking_host,
       substring(p.`host`, instr(p.`host`, ':') + 1)               blocking_port,
       if(p.command = 'sleep', p.time, 0)                          idle_in_trx,
       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_lock_id
         inner join information_schema.innodb_trx r on r.trx_id = w.requesting_trx_id
         inner join information_schema.innodb_locks l on l.lock_id = w.requested_lock_id
         left join information_schema.`processlist` p on p.id = b.trx_mysql_thread_id
order by wait_time desc;

每日一言

"<!doctype html> <html lang="Zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="noindex,nofollow"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <meta name="renderer" content="webkit"> <title>您请求的文件不存在!</title> <link type="text/css" rel="stylesheet" href="https://www.oick.cn/css/404.css" /> <link rel="shortcut icon" href="http://www.oick.cn/favicon.ico" type="image/x-icon" /> </head> <body> <div id="wrap"> <div> <img src="https://www.oick.cn/imgs/404.png" alt="404" /> </div> <div id="text"> <strong> <span></span> <a href="javascript:history.back()">返回上一页</a> </strong> </div> </div> <div class="animate below"></div> <div class="animate above"></div> </body> </html>"

...

站点统计

本周更新文章: 0 篇
文章总数: 59110 篇
今日访问量: 24327 次
访问总量: 182200 次