Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count open db connections?

I'm developing a web app using Java servlet to access Mysql db, how can I get the number of connections to my DB that is currently open ?

Edit :

I tried "show processlist", it showed me : 2695159, but that's not right, I'm just developing this new project, I'm the only user, couldn't have that many processes running, what I want is the number of users accessing my project's DB, not the number of all db users, but just the ones logged in to my database which has only one table.

like image 370
Frank Avatar asked Nov 06 '08 19:11

Frank


People also ask

How many SQL connections are open?

By default, SQL Server allows a maximum of 32767 concurrent connections which is the maximum number of users that can simultaneously log in to the SQL server instance.

How do I find open connections in SQL Server?

In SQL Server Management Studio, right click on Server, choose "Activity Monitor" from context menu -or- use keyboard shortcut Ctrl + Alt + A .

How do I monitor the number of connections in SQL Server?

SELECT * FROM sys. dm_os_performance_counters WHERE counter_name = 'User Connections'; We can see the results here: You also get it via Performance Monitor directly by looking at these counters.


1 Answers

Depending on your MySQL version, you can perform a select on

SELECT COUNT(*) FROM information_schema.PROCESSLIST;

and you can do a where between the user, database, and host IP.

For example:

USE information_schema;
SELECT COUNT(*) FROM PROCESSLIST WHERE db ="mycase" AND HOST LIKE "192.168.11.174%"
like image 153
Gerryjun Avatar answered Oct 21 '22 21:10

Gerryjun