注:processlist表记录的是mysql正在运行的线程信息,而每一个线程在thread表中都有用线程的一个唯一id,thread_id。enents_statements_current记录唯一id和对应的sql语句sql_text
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




