Home >Database >Mysql Tutorial >What's the Difference Between 'Connections' and 'Threads_connected' in MySQL's SHOW STATUS?

What's the Difference Between 'Connections' and 'Threads_connected' in MySQL's SHOW STATUS?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-18 09:17:02862browse

What's the Difference Between 'Connections' and 'Threads_connected' in MySQL's SHOW STATUS?

MySQL: Interpreting the Results of 'show status - active or total connections?'

When executing SHOW STATUS LIKE 'Con%' in MySQL, you may encounter a substantial number of connections, which can be concerning. Understanding whether this number represents active or total connections is crucial for server performance analysis.

Total Connections

The documentation indicates that the output of SHOW STATUS LIKE 'Con%' displays the total number of connection attempts throughout MySQL's history. This includes both successful and failed connections:

"ConnectionsnThe number of connection attempts (successful or not) to the MySQL server."

Active Connections

To determine the number of active connections, you can refer to the Threads_connected status variable:

"Threads_connectednThe number of currently open connections."
mysql> SHOW STATUS WHERE `variable_name` = 'Threads_connected';
+-------------------+----------+
| Variable_name     | Value   |
+-------------------+----------+
| Threads_connected | 4        |
+-------------------+----------+
1 row in set (0.00 sec)

Alternatively, you can retrieve a list of active connections using the SHOW PROCESSLIST command:

mysql> SHOW PROCESSLIST;
+----+------+-----------------+--------+---------+------+-------+------------------+
| Id | User | Host            | db     | Command | Time | State | Info             |
+----+------+-----------------+--------+---------+------+-------+------------------+
|  3 | root | localhost       | webapp | Query   |    0 | NULL  | show processlist | 
|  5 | root | localhost:61704 | webapp | Sleep   |  208 |       | NULL             | 
|  6 | root | localhost:61705 | webapp | Sleep   |  208 |       | NULL             | 
|  7 | root | localhost:61706 | webapp | Sleep   |  208 |       | NULL             | 
+----+------+-----------------+--------+---------+------+-------+------------------+
4 rows in set (0.00 sec)

The above is the detailed content of What's the Difference Between 'Connections' and 'Threads_connected' in MySQL's SHOW STATUS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn