Get Number of Active Connections in MySQL

Get Number of Active Connections in MySQL

Managing active connections in MySQL is crucial for database administrators to ensure optimal performance and resource allocation. Whether you're monitoring the server's health or troubleshooting performance issues, knowing how to obtain the number of active connections is essential. This tutorial explains how to get the number of active connections in MySQL.

Log in to the MySQL server and execute the following SQL query to retrieve the number of active connections:

SHOW STATUS WHERE `variable_name` = 'Threads_connected';

Output example:

+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 1     |
+-------------------+-------+

More details can be retrieved by using the SHOW command. The query is:

SHOW PROCESSLIST;

Output example:

+----+-----------------+-----------------+------+---------+------+------------------------+------------------+---------+-----------+---------------+
| Id | User            | Host            | db   | Command | Time | State                  | Info             | Time_ms | Rows_sent | Rows_examined |
+----+-----------------+-----------------+------+---------+------+------------------------+------------------+---------+-----------+---------------+
|  5 | event_scheduler | localhost       | NULL | Daemon  | 3834 | Waiting on empty queue | NULL             | 3833238 |         0 |             0 |
| 12 | root            | localhost:37502 | NULL | Query   |    0 | init                   | SHOW PROCESSLIST |       0 |         0 |             0 |
+----+-----------------+-----------------+------+---------+------+------------------------+------------------+---------+-----------+---------------+

Leave a Comment

Cancel reply

Your email address will not be published.