我正在尝试确定我的数据库上的连接数,我发现以下查询和网络结果都有非常不同的输出。谁能告诉我哪个数字正确显示数据库上的连接数以及如何获取有关这些连接的更多详细信息?
mysql> SELECT SUBSTRING_INDEX(host, ':', 1) AS host_short,
-> GROUP_CONCAT(DISTINCT USER) AS users,
-> COUNT(*)
-> FROM information_schema.processlist
-> GROUP BY host_short
-> ORDER BY COUNT(*),
-> host_short;
+------------+-------------+----------+
| host_short | users | COUNT(*) |
+------------+-------------+----------+
| localhost | root,mailer | 7 |
+------------+-------------+----------+
1 row in set (0.01 sec)
mysql> show status like 'Conn%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Connections | 9885 |
+---------------+-------+
1 row in set (0.00 sec)
答案 0 :(得分:0)
我使用像bellow -
这样的查询找到了所需的结果SELECT
db_name(dbid) as DBName,
COUNT(dbid) as ConnNo,
loginame as Login
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
;