程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> MySQL如何查詢當前正在運行的SQL語句

MySQL如何查詢當前正在運行的SQL語句

編輯:關於MYSQL數據庫
通過status命令,查看Slow querIEs這一項,如果值長時間>0,說明有查詢執行時間過長

以下為引用的內容:

MySQL> status;
--------------
MySQL Ver 11.18 Distrib 3.23.58, for redhat-Linux-gnu (i386)
Connection id: 53
Current database: (null)
Current user: root@localhost
Current pager: stdout
Using outfile: ''
Server version: 5.0.37-log
Protocol version: 10
Connection: Localhost via UNIX socket
ClIEnt characterset: latin1
Server characterset: latin1
UNIX socket: /tmp/MySQL.sock
Uptime: 4 days 16 hours 49 min 57 sec
Threads: 1 Questions: 706 Slow querIEs: 0 Opens: 177 Flush tables: 1 Open tables:

52 QuerIEs per second avg: 0.002
--------------

以下為引用的內容:

MySQL> status;
--------------
MySQL Ver 11.18 Distrib 3.23.58, for redhat-Linux-gnu (i386)
Connection id: 53
Current database: (null)
Current user: root@localhost
Current pager: stdout
Using outfile: ''
Server version: 5.0.37-log
Protocol version: 10
Connection: Localhost via UNIX socket
ClIEnt characterset: latin1
Server characterset: latin1
UNIX socket: /tmp/MySQL.sock
Uptime: 4 days 16 hours 49 min 57 sec
Threads: 1 Questions: 706 Slow querIEs: 0 Opens: 177 Flush tables: 1 Open tables:

52 QuerIEs per second avg: 0.002
--------------

  這時再通過show processlist命令來查看當前正在運行的SQL,從中找出運行慢的SQL語句,找到執行慢的語句後,再用explain命令查看這些語句的執行計劃。

  MySQL> show processlist;

  +----+------+-----------+------+---------+------+-------+------------------+

  | Id | User | Host | db | Command | Time | State | Info |

  +----+------+-----------+------+---------+------+-------+------------------+

  | 53 | root | localhost | NULL | Query | 0 | NULL | show processlist |

  +----+------+-----------+------+---------+------+-------+------------------+

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved