探讨:MySQL中如何查询当前正在运行的SQL语句
程序员文章站
2024-02-24 18:04:31
通过status命令,查看slow queries这一项,如果值长时间>0,说明有查询执行时间过长复制代码 代码如下:以下为引用的内容:mysql> statu...
通过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
--------------
这时再通过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 |
+----+------+-----------+------+---------+------+-------+------------------+
复制代码 代码如下:
以下为引用的内容:
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 |
+----+------+-----------+------+---------+------+-------+------------------+