mysql - 找出查询是一个进程,了解它的 PID

标签 mysql debugging cpu-usage

通过使用 htop 命令,我可以看到一个 mysqld 进程占用了超过 500% 的 CPU 使用率,它的 PID 例如是 20456 htop 仅在其旁边显示命令/usr/bin/mysqld

现在,我想做的是检查 PID 发出的查询是什么?我的网站做了很多与数据库相关的事情,我想知道是什么工作导致了这种高 CPU 使用率。有人可以给我指路吗?

我尝试在 mysql 中显示完整的进程列表,但它没有显示该列表中的 PID,所以我不知道该关注什么。

最佳答案

当我查看 threads view manual 时,MySQL 5.7/8.0 接缝对此有原生支持

THREAD_OS_ID

The thread or task identifier as defined by the underlying operating system, if there is one:

THREAD_OS_ID contains the operating system thread ID.

For Windows, THREAD_OS_ID corresponds to the thread ID visible in Process Explorer (https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx).

For Linux, THREAD_OS_ID corresponds to the value of the gettid() function. This value is exposed, for example, using the perf or ps -L commands, or in the proc file system (/proc/[pid]/task/[tid]). For more information, see the perf-stat(1), ps(1), and proc(5) man pages

此外,此 View 还包含一个 PROCESSLIST_ID 列,因此您可以使用 information_schema.processlist 加入它知道哪个查询正在使用哪个操作系统 PID

关于mysql - 找出查询是一个进程,了解它的 PID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54678292/

相关文章:

mysql - 使用选择联合构建 MySQL View

mysql - MySQL 中多列索引中的列顺序

java - 调试java混淆代码

linux - Linux 上的细粒度多核线程执行测量?

macos - eflogin-helper 在 MacBook Pro 上以高 cpu 持续运行

PHP:防止用户获得相同的递增ID

java - Spring JDBC 和 MySQL 中无法使用 SET 关键字

c++ - 使用 Xcode 调试我的代码 C++

php - Docker 和 XDebug 不读取断点 VSCode