MySQL show current connection info
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When people ask for “current connection info” in MySQL, they may mean one of two things: details about the session they are currently using, or a list of active connections on the server. MySQL supports both, and the right command depends on whether you are debugging your own session or monitoring the whole instance.
Get Information About the Current Session
For your own connection, a few built-in functions are often enough.
This returns useful session details:
- '
CONNECTION_ID()is the thread or session id' - '
CURRENT_USER()is the authenticated MySQL account' - '
USER()shows the client-provided account and host string' - '
DATABASE()shows the currently selected database'
If you are debugging permissions, the difference between CURRENT_USER() and USER() is especially important because authentication and account matching may not be what you assume.
Show Active Connections with SHOW PROCESSLIST
If you want to inspect current sessions on the server, use SHOW PROCESSLIST.
Or, if you want the full query text rather than a truncated version:
This output includes columns such as:
- '
Idfor the connection id' - '
Userfor the MySQL account' - '
Hostfor the client source' - '
dbfor the selected database' - '
Commandfor the session activity such asSleeporQuery' - '
Timefor how long the session has been in that state' - '
Statefor the current stage of execution' - '
Infofor the SQL text'
That is usually the fastest way to see whether the server is busy, blocked, or full of idle connections.
Query Connection Data as a Table
If you prefer filtering and ordering like a normal query, use INFORMATION_SCHEMA.PROCESSLIST.
This is useful when you want to find long-running sessions or isolate specific users.
For example, long-running queries can be filtered like this:
Check Connection Counts and Limits
Sometimes the real question is not “who is connected?” but “how many connections are in use right now?”
These status variables help:
Threads_connected shows current open connections. Threads_running shows how many threads are actively doing work. max_connections shows the configured limit.
Those three values are useful when you are diagnosing connection pool issues or server saturation.
Identify Your Current Session in the Process List
You can combine session and server views by filtering the process list with your own connection id.
That gives you the process-list row for the session you are using right now.
Common Pitfalls
A common mistake is using SHOW PROCESSLIST when the real need is only your own connection details. In that case, CONNECTION_ID() and related functions are simpler.
Another pitfall is assuming USER() and CURRENT_USER() mean the same thing. They often match, but in authentication debugging they can differ.
Developers also sometimes focus only on Threads_connected and forget Threads_running, which is more informative when the server appears slow.
Finally, SHOW PROCESSLIST may require privileges to see all sessions. If the output looks incomplete, permissions may be the reason.
Summary
- Use
CONNECTION_ID(),CURRENT_USER(),USER(), andDATABASE()for your current session. - Use
SHOW PROCESSLISTorSHOW FULL PROCESSLISTto inspect active server connections. - Query
INFORMATION_SCHEMA.PROCESSLISTwhen you need filtering or ordering. - Check
Threads_connected,Threads_running, andmax_connectionsfor connection health. - Filter the process list by
CONNECTION_ID()if you want the server-side row for your own session.
Related reading

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.