Linux系统电脑
MYSQL数据库
为了浏览当前正在运行的查询,登陆到MySQL终端,然后运行‘show processlist’命令:mysql> show processlist; +--------+--------+-----------------+---------+---------+-------+-------+------------------+-----------+---------------+-----------+| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined | Rows_read |+--------+--------+-----------------+---------+---------+-------+-------+------------------+-----------+---------------+-----------+| 78233 | root | 127.0.0.1:37527 | mysql | Sleep | 16474 | | NULL | 6 | 6 | 6 || 84546 | root | 127.0.0.1:48593 | mysql | Sleep 亲驼 | 13237 | | NULL 冷三 | 2 | 2 | 2 || 107083 | root | 127.0.0.1:56451 | mysql | Sleep | 15488 | | NULL | 1 | 121 | 121 || 131455 | root | 127.0.0.1:48550 | NULL | Query | 0 | NULL | show processlist | 0 | 0 | 0 |+--------+--------+-----------------+---------+---------+-------+-------+------------------+-----------+---------------+-----------+4 rows in set (0.03 sec)
首先你应该查看'Time'项,这里记录了进程执行 '做其当做的事情' 操作的秒数。‘command’项处于‘Sleep’ 状态的进程表示其正在等待接受查询,因此,它并没有消耗任何资源。对于其他任何进程而言,‘Time’超过一定的秒数表明出现问题。
在上面的例子中,唯一运行的查询是我们的‘show processlist’命令。让我们来看看如果我们有一个写的很烂的查询是怎么样的:mysql> show processlist; +--------+--------+-----------------+-----------+---------+-------+--------------+----------------------------------+-----------+---------------+-----------+| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined | Rows_read |+--------+--------+-----------------+-----------+---------+-------+--------------+----------------------------------+-----------+---------------+-----------+| 78233 | root | 127.0.0.1:37527 | example | Sleep | 18046 | | NULL 膨吐忌 | 6 | 6 | 6 || 84546 | root | 127.0.0.1:48593 | example | Sleep | 14809 | | NULL | 2 | 2 | 2 || 107083 | root | 127.0.0.1:56451 | example | Sleep | 17060 | | NULL | 1 | 121 | 121 || 132033 | root | 127.0.0.1:54642 | example | Query | 27 | Sending data | select max(subtotal) from orders | 0 | 0 | 0 || 133933 | root | 127.0.0.1:48679 | NULL | Query | 0 | NULL | show processlist | 0 | 0 | 0 || 134122 | root | 127.0.0.1:49264 | example | Sleep | 0 | | NULL | 0 | 0 | 0 |+--------+--------+-----------------+-----------+---------+-------+--------------+----------------------------------+-----------+---------------+-----------+6 rows in set (0.00 sec)
注意 由于我们没有改变任何数据,MySQL总是报告0行被影响。