如何在H2/MySQL中查找活动的数据库连接数

7

如何查找H2/MySQL中活动的数据库连接数量。我们需要这些信息来确定是否存在连接泄漏。

1个回答

18

对于 H2,使用:

select * from information_schema.sessions;

对于 MySQL,请使用:

show full processlist;
或者
select * from information_schema.processlist;

如果您只对会话数量感兴趣,请使用 select count(*) 而不是 select *


选择从information_schema.sessions; ID USER_NAME SESSION_START STATEMENT STATEMENT_START
2 USER1 2011-05-27 09:09:44.98 null 2011-05-27 09:09:48.139 3 USER1 2011-05-27 10:56:32.769 选择
从information_schema.sessions 2011-05-27 10:56:34.316
- Joe
当我运行上述SQL语句时,我得到了上述信息,但没有得到关于连接计数的信息。我有什么遗漏吗? - Joe
select count(*) from information_schema.sessions; select count(*) from information_schema.processlist;从information_schema.sessions中选择计数(*); 从information_schema.processlist中选择计数(*); - Thomas Mueller

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接