ITPub博客

首页 > 数据库 > MySQL > 结合操作系统线程 查看mysql中的sql资源 消耗

结合操作系统线程 查看mysql中的sql资源 消耗

原创 MySQL 作者:T1YSL 时间:2021-05-18 14:30:35 0 删除 编辑

结合操作系统线程 查看mysql中的sql资源 消耗  (5.7 才可以, 5.7时  performance_schema.threads表 才加入的 thread_os_id 系统线程字段)

 --1、执行一个大sql

mysql> update test_limit_table set b=round(rand()*b,0);


--2、查看cpu高的线程是 2142,top -H 的时候 此时PID不是进程ID 而是线程id(LWP id)

[root@hostmysql80 mysql]# top -H

......                                                    

2142 mysql     20   0 2195448  74992   2348 R 83.1 26.4   0:03.78 mysqld                                                                                                                         

--3、查看 2142线程的 具体的sql

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 =2142; 

 

   





来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69990629/viewspace-2772759/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: mysql 1129处理
请登录后发表评论 登录
全部评论
中国开源软件推进联盟PG分会系列技术丛书《快速掌握PostgreSQL版本新特性》一书副主编。数据库技术专家。数据库认证讲师、恩墨学院数据库讲师。擅长MySQL数据库、PostgreSQL等开源数据库。拥有MySQL-OCP 、PostgreSQL-PGCM等数据库认证。

注册时间:2020-12-12

  • 博文量
    152
  • 访问量
    160713