๐Ÿช„ MySQL SHOW PROCESSLIST Command โ€“ Monitor Active Connections & Queries


๐Ÿงฒ Introduction โ€“ Why Use SHOW PROCESSLIST?

In a live database environment, knowing which users are connected, what queries they are running, and which processes are causing bottlenecks is essential for diagnosing issues and improving performance. The SHOW PROCESSLIST command in MySQL allows DBAs and developers to inspect and monitor all active threads (processes) connected to the server.

๐ŸŽฏ In this guide, youโ€™ll learn:

  • What the SHOW PROCESSLIST command does
  • How to interpret each column
  • Use cases for performance monitoring and troubleshooting
  • How to kill problematic queries
  • Best practices for production use

๐Ÿ”Ž Syntax โ€“ Basic Usage

SHOW PROCESSLIST;

Or to view full queries (not truncated):

SHOW FULL PROCESSLIST;

๐Ÿง  You need PROCESS privilege to see all threads. Without it, youโ€™ll only see your own.


๐Ÿ“Š Output Columns Explained

ColumnDescription
IdUnique thread ID of the connection
UserMySQL username running the process
HostIP or hostname and port of the client
DbThe default database in use (can be NULL)
CommandThe command being executed (e.g., Query, Sleep, Connect, etc.)
TimeDuration in seconds that the process has been in its current state
StateDescription of what the thread is doing (e.g., “Sending data”, “Locked”)
InfoThe actual SQL query or command being executed (can be NULL)

โœ… Example Output

SHOW FULL PROCESSLIST;
IdUserHostDbCommandTimeStateInfo
10rootlocalhost:55212testQuery5Sending dataSELECT * FROM large_table;
11appusr192.168.1.50:592shopSleep80NULL
12rootlocalhost:55215NULLQuery0initSHOW FULL PROCESSLIST

๐Ÿšฆ Common Command Values

CommandMeaning
QueryActively running SQL command
SleepConnection is idle
ConnectWaiting for client to send login info
Binlog DumpReplication-related thread
KillThread is being terminated

๐Ÿšจ Use Cases โ€“ Why This Matters

๐Ÿข Find Long-Running Queries

SHOW FULL PROCESSLIST;

Sort by Time to identify queries that are running too long.

๐Ÿ”’ Identify Locked Queries

Look for State = "Locked" โ€” these may indicate deadlocks or waiting transactions.

โš”๏ธ Kill a Problematic Process

KILL 10;

Kills thread with Id = 10. โš ๏ธ Use cautiously โ€” it rolls back any ongoing transaction.


๐Ÿ“˜ Best Practices

โœ… Use SHOW FULL PROCESSLIST to view complete SQL queries
๐Ÿง  Filter results by writing:

SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND != 'Sleep';

๐Ÿ”’ Grant only necessary users the PROCESS privilege to avoid exposing all sessions

๐Ÿ” Automate query logging using slow_query_log or performance_schema for large apps


๐Ÿงช Real-World Applications

ScenarioAction with SHOW PROCESSLIST
Website running slowCheck for long SELECT queries or locked rows
DB connection pool maxed outLook for excessive Sleep connections
Unexpected server CPU spikeDetect Query threads consuming resources
Replication lagObserve Binlog Dump status

๐Ÿ“Œ Summary โ€“ Recap & Next Steps

The SHOW PROCESSLIST command gives you a real-time snapshot of all active and idle threads in your MySQL server. Itโ€™s indispensable for troubleshooting, performance tuning, and live monitoring.

๐Ÿ” Key Takeaways

  • Use SHOW FULL PROCESSLIST for full query visibility
  • Check Time and State to detect long or stuck queries
  • Use KILL to stop problematic threads (with caution)
  • Automate log monitoring in production setups

โš™๏ธ Real-World Relevance
Every serious MySQL application benefits from active monitoring using SHOW PROCESSLIST. It gives DBAs instant insight into server health.


โ“ FAQ โ€“ MySQL SHOW PROCESSLIST

โ“ What privilege is required to see all processes?
โœ… You need the PROCESS privilege to view all threads.

โ“ Is it safe to kill a thread using KILL?
โš ๏ธ Yes, but it rolls back any active transaction. Always verify before killing.

โ“ How can I detect sleeping connections?
โœ… Look for Command = 'Sleep'. These are idle connections that may exhaust resources.

โ“ How often should I run SHOW PROCESSLIST?
โœ… In dev or testing: as needed. In production: use monitoring tools like Percona, PMM, or Performance Schema.

โ“ Can I view this information programmatically?
โœ… Yes. Query from INFORMATION_SCHEMA.PROCESSLIST.


Share Now :
Share

๐Ÿช„ MySQL Show Processlist Command

Or Copy Link

CONTENTS
Scroll to Top