日期:2014-05-16  浏览次数:20819 次

Mysql-命令查询当前正在负载运行的SQL语句

1)我们先通过status命令查看Mysql运行状态,如下:

mysql> status;
--------------
mysql??Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (x86_64) using readline 5.1

Connection id:??????????19878
Current database:
Current user:???????????root@localhost
SSL:????????????????????Not in use
Current pager:??????????stdout
Using outfile:??????????''
Using delimiter:????????;
Server version:?????????5.0.77 Source distribution
Protocol version:???????10
Connection:?????????????Localhost via UNIX socket
Server characterset:????latin1
Db?????characterset:????latin1
Client characterset:????latin1
Conn.??characterset:????latin1
UNIX socket:????????????/var/lib/mysql/mysql.sock
Uptime:?????????????????312 days 31 min 37 sec

Threads: 1??Questions: 107979??Slow queries: 0??Opens: 17??Flush tables: 1??Open tables: 11?Queries per second avg: 0.004
--------------
在上面显示列表的最后一条,我们来查看Slow queries这一项的值,如果多次查看的值大于0的话,说明有些查询sql命令执行时间过长。

?

2)这时再通过show processlist命令来查看当前正在运行的SQL,从中找出运行慢的SQL语句,找到执行慢的语句后,再用explain命令查看这些语句的执行计划。

mysql> show processlist;
+-------+------+-----------+------+---------+------+-------+------------------+
| Id????| User | Host??????| db???| Command | Time | State | Info?????????????|
+-------+------+-----------+------+---------+------+-------+------------------+
| 19878 | root | localhost | NULL | Query???|????0 | NULL??| show processlist |
+-------+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)