需要看你的操作系统的API手册了,如果用脚本的话, WIDNOWS 2003下你可以用tasklist 得到所有的进程 linux 下你可以 ps -aux 得到进行信息。每5分钟查一次,然后把这些数据写入到数据库中。或者现在有一些专门的系统监视软件,你可以找一下看看。
介绍个给你 Nagios不错的软件
mysql> show processlist; +----+-----------------+----------------+------+---------+-------+-------------------------- | Id | User | Host | db | Command | Time | State +----+-----------------+----------------+------+---------+-------+-------------------------- | 1 | event_scheduler | localhost | NULL | Daemon | 814 | Waiting for next activati | 6 | root | localhost:2345 | test | Sleep | 10262 | | 7 | root | localhost:2346 | NULL | Sleep | 11177 | | 16 | root | localhost:3133 | test | Query | 0 | NULL +----+-----------------+----------------+------+---------+-------+-------------------------- 4 rows in set (0.00 sec) 显示的是数据库进程
要简单点的方法,不用那么复杂的,nianzhang747的数据库里面没有进程名啊
mysql> show processlist; +----+------+----------------+------+---------+------+-------+------------------ + | Id | User | Host | db | Command | Time | State | Info | +----+------+----------------+------+---------+------+-------+------------------ + | 3 | root | localhost:2900 | test | Query | 0 | NULL | show processlist | +----+------+----------------+------+---------+------+-------+------------------ + 1 row in set (0.00 sec)mysql> kill 3; Query OK, 0 rows affected (0.00 sec)mysql> show processlist; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 4 Current database: test+----+------+----------------+------+---------+------+-------+------------------ + | Id | User | Host | db | Command | Time | State | Info | +----+------+----------------+------+---------+------+-------+------------------ + | 4 | root | localhost:2902 | test | Query | 0 | NULL | show processlist | +----+------+----------------+------+---------+------+-------+------------------ + 1 row in set (0.20 sec)
楼主指的是操作系统上的进程吧。这个没办法仅通过mysql内部的语言来实现。楼主的操作系统是什么? windows / linux / unix ??
WIDNOWS 2003下你可以用tasklist 得到所有的进程
linux 下你可以 ps -aux 得到进行信息。每5分钟查一次,然后把这些数据写入到数据库中。或者现在有一些专门的系统监视软件,你可以找一下看看。
+----+-----------------+----------------+------+---------+-------+--------------------------
| Id | User | Host | db | Command | Time | State
+----+-----------------+----------------+------+---------+-------+--------------------------
| 1 | event_scheduler | localhost | NULL | Daemon | 814 | Waiting for next activati
| 6 | root | localhost:2345 | test | Sleep | 10262 |
| 7 | root | localhost:2346 | NULL | Sleep | 11177 |
| 16 | root | localhost:3133 | test | Query | 0 | NULL
+----+-----------------+----------------+------+---------+-------+--------------------------
4 rows in set (0.00 sec)
显示的是数据库进程
+----+------+----------------+------+---------+------+-------+------------------
+
| Id | User | Host | db | Command | Time | State | Info
|
+----+------+----------------+------+---------+------+-------+------------------
+
| 3 | root | localhost:2900 | test | Query | 0 | NULL | show processlist
|
+----+------+----------------+------+---------+------+-------+------------------
+
1 row in set (0.00 sec)mysql> kill 3;
Query OK, 0 rows affected (0.00 sec)mysql> show processlist;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 4
Current database: test+----+------+----------------+------+---------+------+-------+------------------
+
| Id | User | Host | db | Command | Time | State | Info
|
+----+------+----------------+------+---------+------+-------+------------------
+
| 4 | root | localhost:2902 | test | Query | 0 | NULL | show processlist
|
+----+------+----------------+------+---------+------+-------+------------------
+
1 row in set (0.20 sec)