How can I see how many MySQL connections are open?

前端 未结 5 1361
甜味超标
甜味超标 2020-12-12 20:35

How can I see how many connections have been opened during the current request via mysql_connect in PHP running on Apache?

I know that if I call m

5条回答
  •  渐次进展
    2020-12-12 21:34

    There are other useful variables regarding connections and in your particular case variable Connections might help find out if your code is making too many connections. Just check it value before and after running code.

    # mysql -e 'SHOW STATUS WHERE variable_name LIKE "Threads_%" OR variable_name = "Connections"'
    
    +-------------------+-------+
    | Variable_name     | Value |
    +-------------------+-------+
    | Connections       | 22742 |
    | Threads_cached    | 1     |
    | Threads_connected | 87    |
    | Threads_created   | 549   |
    | Threads_running   | 51    |
    +-------------------+-------+
    
    • Connections

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

    • Threads_cached

      The number of threads in the thread cache.

    • Threads_connected

      The number of currently open connections.

    • Threads_created

      The number of threads created to handle connections. If Threads_created is big, you may want to increase the thread_cache_size value. The cache miss rate can be calculated as Threads_created/Connections.

    • Threads_running

      The number of threads that are not sleeping.

提交回复
热议问题