转载地址: 如何查找MySQL数据库耗费CPU的SQL_ITPUB博客
1.Top -H -p pid
查找到耗费cpu资源的mysqld进程里的线程id
例如是
2122 mysql 20 0 2195448 74992 2348 R 83.1 26.4 0:03.78 mysqld
2.查看 2122线程的 具体的sql
( 线程类型,分为BACKGROUND(后台线程)和FOREGROUND(用户线程),我们要关注的是用户线程)
mysql> SELECT a.name,
a.thread_id,
a.thread_os_id,
a.processlist_id,
a.type,
b.user,
b.host,
b.db,
b.command,
b.time,
b.state,
b.info
FROM performance_schema.threads a
LEFT JOIN information_schema.processlist b
ON a.processlist_id = b.id
where a.type = 'FOREGROUND'
and a.thread_os_id =2122;
