show [full] processlist

show processlist显示正在运行的线程。如果有process权限,则可以查看所有正在运行的线程。否则,只能看到自己的线程。如果不使用full关键字,则只在info字段显示每个语句的前100个字符。

show processlist命令是非常有用的,如果你获得到“too many connections”错误信息,并且想知道什么正在运行。MySQL保留了一个额外的连接给超级管理员。

线程能够被kill掉,使用kill语句。

mysql> show processlist;
+----+------+--------------------+-----------+---------+------+-------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+--------------------+-----------+---------+------+-------------+------------------+
| 36 | root | 172.16.100.19:7954 | tpcc_test | Sleep | 456 | | NULL |
| 37 | root | 172.16.100.19:7969 | tpcc_test | Sleep | 456 | | NULL |
| 42 | root | localhost | NULL | Query | 0 | System lock | show processlist |
| 43 | root | 10.0.102.204:49224 | employees | Sleep | 12 | | NULL |
+----+------+--------------------+-----------+---------+------+-------------+------------------+
4 rows in set (0.00 sec)

这个显示的几个字段还是比较好理解的。

  • ID:连接标识。这个值和INFORMATION_SCHEMA.PROCESSLIST表的ID列,以及PERFORMANCE_SCHEMA中的threads中的process_id值是相同的。
  • user: 发出该语句的MySQL用户。system user是指由服务器生成的用于内部处理任务的非客户端线程。这可以是用于复制的I/O线程,或SQL线程,也可以是延迟的行处理程序。未经身份验证的用户是指已经与客户端连接但尚未对客户端身份进行验证的线程。
  • Host:客户端使用的主机。系统用户没有host值。
  • db:连接的数据库。
  • command:线程执行的命令
    A thread can have any of the following Command values:
    
    Binlog Dump:  This is a thread on a master server for sending binary log contents to a slave server.
    
    Change user: The thread is executing a change-user operation.
    
    Close stmt: The thread is closing a prepared statement.[关闭准备好的声明]
    
    Connect:A replication slave is connected to its master. 【已经连接】
    
    Connect Out:A replication slave is connecting to its master. 【正则连接】
    
    Create DB:The thread is executing a create-database operation.
    
    Daemon:This thread is internal to the server, not a thread that services a client connection. 【这个线程是服务器内部线程,而不是客户端线程】
    
    Debug:The thread is generating debugging information. 【线程正在生成调试信息】
    
    Delayed insert:The thread is a delayed-insert handler.【延迟插入处理】
    
    Drop DB:The thread is executing a drop-database operation.
    
    Error:
    
    Execute:The thread is executing a prepared statement. 【线程正在执行预准备的语句】
    
    Fetch:The thread is fetching the results from executing a prepared statement.【线程正在从预准备语句拉取结果】
    
    Field List:The thread is retrieving information for table columns.【该线程正则检索列表信息】
    
    Init DB:The thread is selecting a default database. 【线程正在选择一个默认数据库】
    
    Kill:The thread is killing another thread. 【线程正则kill掉其他线程】
    
    Long Data:The thread is retrieving long data in the result of executing a prepared statement.
    
    Ping:The thread is handling a server-ping request.
    
    Prepare:The thread is preparing a prepared statement.
    
    Processlist:The thread is producing information about server threads.
    
    Query: The thread is executing a statement.
    
    Quit:The thread is terminating.
    
    Refresh:The thread is flushing table, logs, or caches, or resetting status variable or replication server information.
    
    Register Slave: The thread is registering a slave server.
    
    Reset stmt: The thread is resetting a prepared statement.
    
    Set option: The thread is setting or resetting a client statement-execution option.
    
    Shutdown: The thread is shutting down the server.
    
    Sleep: The thread is waiting for the client to send a new statement to it.
    
    Statistics:The thread is producing server-status information.
    
    Table Dump:The thread is sending table contents to a slave server.
    
    Time:Unused.

    command的取值

  • time: 线程已经在当前状态的时间。
  • state:一个动作,一个事件,标识线程正在做什么。https://blog.csdn.net/sunqingzhong44/article/details/70570728
  • info:Info contains the text of the statement being executed by the thread, or NULL if it is not executing one. By default, this value contains only the first 100 characters of the statement. To see the complete statements, useSHOW FULL PROCESSLIST.

进程的信息也可以通过mysqladmin processlist命令查看。

相比较之下show processlist和information_schema.processlist需要互斥锁,而performance_schema.threads不需要,threads对服务器性能影响最小,threads表还显示有关后台线程的信息。

kill线程

与MySQL服务器每个链接都在一个单独的线程中运行。可以使用如下语句杀死一个线程。

kill [connection| query] processlist_id

connection: 与kill processlist_id相同;中断连接正在执行的任何语句之后,中断连接。
query: 中断连接正在执行的语句,但是保持本身的连接。

有三种方法可以获得processlist_id,上面已经提到了!

当你使用kill时,一个特殊的kill标记被设置给这个线程。在大多数的情况下,它可能会等一段时间线程再死亡,因为kill标记仅在一些情况下被检测。

  • During SELECT operations, for ORDER BY and GROUP BY loops, the flag is checked after reading a block of rows. If the kill flag is set, the statement is aborted.
  • ALTER TABLE operations that make a table copy check the kill flag periodically for each few copied rows read from the original table. If the kill flag was set, the statement is aborted and the temporary table is deleted.The KILL statement returns without waiting for confirmation, but the kill flag check aborts the operation within a reasonably small amount of time. Aborting the operation to perform any necessary cleanup also takes some time.
  • During UPDATE or DELETE operations, the kill flag is checked after each block read and after each updated or deleted row. If the kill flag is set, the statement is aborted. If you are not using transactions, the changes are not rolled back.
  • GET_LOCK() aborts and returns NULL.
  • If the thread is in the table lock handler (state: Locked), the table lock is quickly aborted.
  • If the thread is waiting for free disk space in a write call, the write is aborted with a “disk full” error message.
mysql> show processlist;
+----+------+---------------------+--------------------+---------+------+-------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+---------------------+--------------------+---------+------+-------------+------------------+
| 36 | root | 172.16.100.19:7954 | tpcc_test | Sleep | 8 | | NULL |
| 37 | root | 172.16.100.19:7969 | tpcc_test | Sleep | 8 | | NULL |
| 42 | root | localhost | NULL | Query | 0 | System lock | show processlist |
| 43 | root | 10.0.102.204:49224 | employees | Sleep | 2564 | | NULL |
| 44 | root | 172.16.100.19:14529 | NULL | Sleep | 2322 | | NULL |
| 45 | root | 172.16.100.19:14770 | information_schema | Sleep | 2315 | | NULL |
| 46 | root | 172.16.100.19:1508 | information_schema | Sleep | 2314 | | NULL |
| 47 | root | 172.16.100.19:10572 | performance_schema | Sleep | 2231 | | NULL |
| 48 | root | 172.16.100.19:11392 | performance_schema | Sleep | 2231 | | NULL |
+----+------+---------------------+--------------------+---------+------+-------------+------------------+
9 rows in set (0.00 sec) mysql> kill 43; #kill掉43线程
Query OK, 0 rows affected (0.00 sec)

mysql> show processlist;
+----+------+---------------------+--------------------+---------+------+-------------+------------------+
| Id | User | Host                | db                 | Command | Time | State       | Info             |
+----+------+---------------------+--------------------+---------+------+-------------+------------------+
| 36 | root | 172.16.100.19:7954  | tpcc_test          | Sleep   |  386 |             | NULL             |
| 37 | root | 172.16.100.19:7969  | tpcc_test          | Sleep   |  386 |             | NULL             |
| 42 | root | localhost           | NULL               | Query   |    0 | System lock | show processlist |
| 44 | root | 172.16.100.19:14529 | NULL               | Sleep   | 3300 |             | NULL             |
| 45 | root | 172.16.100.19:14770 | information_schema | Sleep   | 3293 |             | NULL             |
| 46 | root | 172.16.100.19:1508  | information_schema | Sleep   | 3292 |             | NULL             |
| 47 | root | 172.16.100.19:10572 | performance_schema | Sleep   | 3209 |             | NULL             |
| 48 | root | 172.16.100.19:11392 | performance_schema | Sleep   | 3209 |             | NULL             |
+----+------+---------------------+--------------------+---------+------+-------------+------------------+
8 rows in set (0.00 sec) MySQL [employees]> select * from employees; #连接发现失败
ERROR 2013 (HY000): Lost connection to MySQL server during query

show processlist命令与kill 线程的更多相关文章

  1. 显示mysql线程和kill线程的命令

    show processlist;//显示哪些线程正在运行. kill id //kill线程   通常在表被锁的时候用.   show processlist;显示哪些线程正在运行.您也可以使用my ...

  2. MySQL show processlist命令详解

    show processlist; 命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 方式1:进入mysql/bin目录下输入mysqladmin proc ...

  3. mysql show processlist命令 详解

    SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...

  4. mysql show processlist 命令检查mysql lock

    processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 1. 进入mysql/bin目录下输入mysqladmin processlist; ...

  5. 通过mysql show processlist 命令检查mysql锁的方法

    作者: 字体:[增加 减小] 类型:转载 时间:2010-03-07 show processlist 命令非常实用,有时候mysql经常跑到50%以上或更多,就需要用这个命令看哪个sql语句占用资源 ...

  6. 命令格式 kill -3 pid

    命令格式 kill -3 pid 作用 打印进程号为pid的进程中,每个线程的执行日志 到 nohup文件 中,如果nohup的输出做了重定向,那么输出到重定向以后的文件中. 命令格式 top -Hp ...

  7. Mysql Show ProcessList命令

    每个MySql连接,或者叫线程,在任意一个给定的时间都有一个状态来标识正在进行的事情.可以使用 SHOW [FULL] PROCESSLIST 命令来查看哪些线程正在运行,及其查询状态,Command ...

  8. TiDB show processlist命令源码分析

    背景 因为丰巢自去年年底开始在推送平台上尝试了TiDB,最近又要将承接丰巢所有交易的支付平台切到TiDB上.我本人一直没有抽出时间对TiDB的源码进行学习,最近准备开始一系列的学习和分享.由于我本人没 ...

  9. Mysql processlist命令

    Mysql processlist命令   mysqladmin -uroot -proot processlist mysql 查看当前连接数 命令: show processlist; 如果是ro ...

随机推荐

  1. Spark之数据倾斜 --采样分而治之解决方案

    1 采样算法解决数据倾斜的思想 2 采样算法在spark数据倾斜中的具体操作

  2. [django]梳理drf知识点

    要实现的功能 idc_list/ get 列出所有 post 创建一个idc idc_detail/1/ get 获取一个idc put 修改一个idc delete 删除一个idc 一般url是这样 ...

  3. [sh]rm -rf*的防护和普通用户执行命令

    尽量用普通用户执行,因为普通用户无法删除root的文件,避免误删除 rm -rf 不可取, 尽量find+rm -rf 尽量cd && rm -rf * 加上逻辑 cd /tmp/re ...

  4. 收藏住:金融&电商类原型模板重磅来袭,免费使用!

    经常有很多产品经理和设计师想要各行业的产品原型模板,可以直接下载使用.现在分享下一个资源渠道:墨刀的原型模板. 上新了金融类和电商类的主要App设计原型,可以直接免费使用,具体包括: 金融类 招商银行 ...

  5. python SMTP other

    HTML 正文,带链接和图片 //test.py import smtplib from email.mime.image import MIMEImage from email.mime.text ...

  6. React对比Vue(04 父子组件的通信 )

    跟vue差不多 都是props,但是react里面不仅可以给子组件传值,还可以传方法,MD尽然还可以把自己传给子组件,(卧槽vue可没有这个啊 )  vue的传递值差不多,传方法就不用了,子组件可以掉 ...

  7. cocos2dx 3.x(for 循环让精灵从中间往上下两边排列)

    最近很多游戏都喜欢房卡类的游戏,就是创建房间时(),选择玩法与规则,今天耗费2小时处理这个数学问题:例如选择规则两条,则背景框中间显示两条规则,若选择三条,则背景框中间显示三条规则与玩法,依次从中间往 ...

  8. response.sendRedirect(url)与request.getRequestDispatcher(url).forward(request,response)的区别

    response.sendRedirect(url)跳转到指定的URL地址,产生一个新的request,所以要传递参数只有在url后加参数,如: url?id=1.request.getRequest ...

  9. Window.sessionStorage - Web API 接口参考 | MDN

    参考:https://developer.mozilla.org/zh-CN/docs/Web/API/Window/sessionStorage sessionStorage 属性允许你访问一个 s ...

  10. 删掉centos原有的openjdk并安装sun jdk

    [环境变量]删掉centos原有的openjdk并安装sun jdk   一.卸载原有openjdk rpm -qa | grep java 之后,将展示出来的全部卸载掉,我这里是5个 rpm -e ...