Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the active number of open database connections in H2/MySQL

Tags:

mysql

h2

How to find the active number of open database connections in H2/MySQL. We need this information to identify if there are any connection leaks.

like image 815
Joe Avatar asked May 26 '11 11:05

Joe


People also ask

How can I see active connections in MySQL?

The active or total connection can be known with the help of threads_connected variable. The variable tells about the number of currently open connections. mysql> show status where `variable_name` = 'Threads_connected'; Here is the output.

How do I check my H2 database console?

Access the H2 Console You can access the console at the following URL: http://localhost:8080/h2-console/. You need to enter the JDBC URL, and credentials. To access the test database that the greeter quickstart uses, enter these details: JDBC URL: jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1.

How many connections can a database have?

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 know if H2 is running?

Step 3: Verify H2 Database InstallationClick Windows → type H2 Console → Click H2 console icon. Connect to the URL http://localhost:8082. At the time of connecting, the H2 database will ask for database registration as shown in the following screenshot.


1 Answers

For H2, use:

select * from information_schema.sessions;

For MySQL, use:

show full processlist;

or

select * from information_schema.processlist;

If you are just interested in the session count, use select count(*) instead of select *

like image 114
Thomas Mueller Avatar answered Nov 01 '22 11:11

Thomas Mueller