网站首页 > 知识剖析 正文
mysql快速定位cpu 占比过高的sql语句
当MySQL数据库的CPU使用率异常升高时,需要快速定位SQL有问题的语句
1、使用top命令找出mysl进程中占用CPU靠前的线程
#找出mysql 的进程号
ps -ef | grep mysql
#根据进程号,找出占用CPU靠前的线程号
top -H -p <mysqld进程id>
top 中,按大写的P ,进行CPU 使用率排序
找到线程ID 号,为39449
2、登录到数据库查询performance_schema和information_schema
-- 查询性能模式中的线程信息
select * from performance_schema.threads;
-- 查询当前运行的进程列表
select * from information_schema.processlist
使用以下SQL语句可以查询到具体的线程信息,包括其操作系统线程ID(thread_os_id)和正在执行的SQL语句:贴入, <具体线程id>
SELECT
a. USER,
a. HOST,
a.db,
b.thread_os_id,
b.thread_id,
a.id processlist_id,
a.command,
a.time,
a.state,
a.info
FROM
information_schema.PROCESSLIST a,
performance_schema.threads b
WHERE
a.id = b.processlist_id
AND b.thread_os_id = <具体线程id>;
猜你喜欢
- 2024-12-18 MySQL面试知识整理,Java程序员升职涨薪必备,附赠架构师成长图
- 2024-12-18 深圳尚学堂:mysql基本sql语句大全(三)
- 2024-12-18 centos下 iptables 超详细教程和使用示例
- 2024-12-18 一次 MySQL 线上死锁分析实战 mysql死锁的原因及解决方法
- 2024-12-18 关于mysqldump,这个参数你可能还不知道
- 2024-12-18 Windows10将兼容Linux原生应用 linux和windows兼容吗
- 2024-12-18 Build 2016:微软演示让Windows 10运行Linux原生应用
- 2024-12-18 Windows命令行包管理工具scoop使用教程
- 2024-12-18 开发者上云优惠:.top与.xyz域名1元/首年,1核2G云服务器48元/年
- 2024-12-18 宝塔面板负载状态显示100%怎么办?MySQL性能优化篇
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)