MySQL show connections: active (Threads_connected) vs total (Connections)
Codemia Knowledge Hub ·
SHOW STATUS LIKE 'Threads_connected' shows active (currently open) connections. SHOW STATUS LIKE 'Connections' shows the total cumulative count of connection attempts since the server started. For "how many clients are connected right now," use Threads_connected. For "how many connections has this server handled since the last restart," use Connections. Confusing the two is a common monitoring mistake.
Connection status variables
These are the connection-related status variables that matter most:
| Variable | What It Measures | Resets On Restart |
Connections | Total connection attempts (successful + failed) since server start | Yes |
Threads_connected | Currently open connections right now | N/A (live gauge) |
Threads_running | Connections actively executing a query right now | N/A (live gauge) |
Max_used_connections | High-water mark for simultaneous connections since server start | Yes |
Aborted_connects | Failed connection attempts (bad password, too many connections, etc.) | Yes |
Aborted_clients | Connections that were closed without proper logout | Yes |
Threads_connected and Threads_running also differ. A connection can be open but idle, waiting for the application to send a query. Threads_connected counts all open connections (active + idle). Threads_running counts only those actively executing a statement.
Checking current connections
How many clients are connected now
This tells you 42 client connections are currently open. Some may be actively querying, others may be idle.
How many are running queries
Out of 42 connected clients, only 5 are executing a query at this moment. The other 37 are idle but holding open connections.
What each connection is doing
Or for the full query text:
This lists every connected thread with its state, current query, and how long it has been in that state. It is the best way to find long-running queries, sleeping connections, and locked threads.
For a more queryable format:
This filters out sleeping (idle) connections and sorts by duration, showing the longest-running active queries first.
Connection limits and capacity
Maximum allowed connections
The default is 151. In production, this is almost always too low.
The high-water mark
This tells you the peak number of simultaneous connections since the last server restart. If this value is close to max_connections, you are at risk of hitting the connection limit.
Connection utilization percentage
This shows how close you are to the limit:
If utilization is consistently above 80%, increase max_connections or implement connection pooling.
Configuring max_connections
At runtime (no restart required)
This takes effect immediately but reverts on server restart.
In the configuration file (persistent)
After editing, restart MySQL or reload the configuration.
Memory per connection
Each connection consumes memory. The rough formula is:
With default settings, each connection uses roughly 1-10 MB depending on the query. Setting max_connections = 10000 on a server with 4 GB of RAM will eventually cause out-of-memory issues if those connections are all active.
Connection pooling
Instead of raising max_connections indefinitely, use a connection pooler. The application maintains a pool of reusable connections, which keeps the total count manageable.
Example: HikariCP (Java)
Example: Connection Pool in Python
Monitoring connections over time
For ongoing monitoring, record these values periodically:
Feed this into Grafana, Datadog, or any time-series monitoring system to track connection trends and catch issues before they become outages.
Monitoring mistakes
Confusing Connections with Threads_connected. Connections is a cumulative counter that only increases. Threads_connected is a live gauge. If someone asks "how many connections do we have," they almost certainly mean Threads_connected.
Setting max_connections too high without considering memory. Each connection reserves memory buffers. A server with 1000 active connections and default buffer sizes can consume several gigabytes of RAM for connections alone, leaving insufficient memory for the InnoDB buffer pool.
Not monitoring Aborted_connects. A high rate of aborted connections often indicates authentication failures, connection storms from misbehaving applications, or clients being rejected because max_connections was reached. It is easy to overlook.
Ignoring idle connections. Applications that open connections without closing them inflate Threads_connected without doing useful work. Use wait_timeout to automatically close idle connections after a configurable period (default is 28800 seconds, which is 8 hours).
Using SHOW PROCESSLIST instead of information_schema.PROCESSLIST for programmatic access. SHOW PROCESSLIST truncates query text to 100 characters and is harder to filter. The information_schema version gives you the full query and can be filtered with standard SQL WHERE clauses.
Related reading
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.