Home  >  Article  >  Database  >  Does SHOW STATUS LIKE 'Con%' Display Active or Total Connections in MySQL?

Does SHOW STATUS LIKE 'Con%' Display Active or Total Connections in MySQL?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-16 09:33:03517browse

Does SHOW STATUS LIKE 'Con%' Display Active or Total Connections in MySQL?

Show Status - Connections: Active or Total?

When running the SHOW STATUS LIKE 'Con%' command in MySQL, it reveals a growing number of connections. This raises the question: does this value represent active connections or total connections made historically?

Answer:

According to MySQL's documentation, the "Connections" value displayed by the SHOW STATUS command refers to the total number of connection attempts made to the server, including both successful and failed attempts.

Determining Active Connections:

To obtain the number of currently active connections, you can use either the Threads_connected status variable or the SHOW PROCESSLIST command.

  • Threads_connected:

    mysql> SHOW STATUS WHERE `variable_name` = 'Threads_connected';
    
    +-------------------+-------+
    | Variable_name     | Value |
    +-------------------+-------+
    | Threads_connected | 4     |
    +-------------------+-------+
  • SHOW PROCESSLIST:

    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             | 
    +----+------+-----------------+--------+---------+------+-------+------------------+

The above is the detailed content of Does SHOW STATUS LIKE 'Con%' Display Active or Total Connections in MySQL?. 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