How can I see how many MySQL connections are open?

前端 未结 5 1357
甜味超标
甜味超标 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:10

    Current connections status:

    mysqladmin status
    

    Look at Threads: count. More detailed information about current connections can be obtained with the commands:

    user@host:~$ mysqladmin -uroot -ppass extended-status | grep Threads
    | Threads_cached                           | 0           |
    | Threads_connected                        | 3           |
    | Threads_created                          | 3           |
    | Threads_running                          | 1           |
    
    user@host:~$ mysqladmin -uroot -ppass processlist
    +----+------+-----------+----+---------+------+-------+------------------+
    | Id | User | Host      | db | Command | Time | State | Info             |
    +----+------+-----------+----+---------+------+-------+------------------+
    | 53 | root | localhost |    | Sleep   | 258  |       |                  |
    | 54 | root | localhost |    | Sleep   | 253  |       |                  |
    | 58 | root | localhost |    | Query   | 0    |       | show processlist |
    +----+------+-----------+----+---------+------+-------+------------------+
    

    FYI mysqladmin -v -uroot -ppass processlist is analog of show full processlist.

    Commands can be shortened to any unique prefix, and called simultaneously:

    user@host:~$ mysqladmin -v -uroot -ppass proc stat
    +----+------+-----------+----+---------+------+-------+-----------------------+
    | Id | User | Host      | db | Command | Time | State | Info                  |
    +----+------+-----------+----+---------+------+-------+-----------------------+
    | 53 | root | localhost |    | Sleep   | 951  |       |                       |
    | 54 | root | localhost |    | Sleep   | 946  |       |                       |
    | 65 | root | localhost |    | Query   | 0    |       | show full processlist |
    +----+------+-----------+----+---------+------+-------+-----------------------+
    Uptime: 1675  Threads: 3  Questions: 171  Slow queries: 0  Opens: 235  
    Flush tables: 1  Open tables: 57  Queries per second avg: 0.102
    

提交回复
热议问题