how to customize `show processlist` in mysql?

前端 未结 6 1075
孤城傲影
孤城傲影 2021-01-29 18:11

I want to order by Time,but seems no way to do that ?

mysql> show processlist;
+--------+-------------+--------------------+------+---------+--------+--------         


        
6条回答
  •  我在风中等你
    2021-01-29 18:38

    ...We don't have a newer version of MySQL yet, so I was able to do this (works only on UNIX):

     host=maindb
    
     echo "show full processlist\G" | mysql -h$host | grep -B 6 -A 1 Locked
    

    The above will query for all locked sessions, and return the information and SQL that is involved.

    ...So- assuming you wanted to query for sessions that were sleeping:

      host=maindb
    
      echo "show full processlist\G" | mysql -h$host | grep -B 6 -A 1 Sleep
    

    Or, assuming you needed to provide additional connection parameters for MySQL:

      host=maindb
    
      user=me
    
      password=mycoolpassword 
    
      echo "show full processlist\G" | mysql -h$host -u$user -p$password | grep -B 6 -A 1 Locked
    

    With a couple of tweaks, I'm sure a shell script could be easily created to query the processlist the way you want it.

提交回复
热议问题