重庆思庄Oracle、、PostgreSQL、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 283|回复: 0
打印 上一主题 下一主题

[命令及语法] mysql线程 连接数

[复制链接]
跳转到指定楼层
楼主
发表于 2025-6-10 14:31:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.查看每个与数据库连接的session状态


show processlist;展示前100条线程


show full processlist; 列出全部线程


2.非sleep状态进程数


select count(1) from information_schema.proceslist where command!='sleep';


3.执行时间较长进程号


select id,time from information_schema.processlit order by time desc limit 5;


4.查看当前运行的所有事务


select * from information_schema.innodb_trx;


5.当前锁


select * from performance_schema.innodb_locks; 8.0之前使用


select * from performance_schema.data_locks; 8.0使用


select * from performance_schema.innodb_lock_waits; 8.0之前使用 锁等待的对应关系


select * from performance_schema.data_lock_waits; 8.0使用 BLOCKING_ENGINE_TRANSACTION_ID被blocking阻塞的事务id


6.数据库连接数


show status like 'Threads_connected';


select count(1) from performance_schema.threads; 每一行记录的是一条服务器线程


7.查看锁状态


show status like 'innodb_row_lock_%';


当前等待锁的数量;系统启动到现在锁定总时间;每次锁定平均时间;最长一次锁定时间;系统启动到现在总次数


8.正在被使用的表


show open tables where in_use>0;


9.快速定位占用cpu过高的sql


1)通过pidstat定位:ps -ef|grep mysqld找到进程pid;然后执行pidstat -t -p $PID


select * from performance_schema.threads where thread_os_id='1'; 找到最终sql


2) 通过top命令,输入H显示线程状态;输入P按照cpu使用时间份额排序


select * from performance_schema.threads where thread_os_id='1'\G

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2025-7-15 22:08 , Processed in 0.091293 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表