How do I inspect MySQL connections and long-running work without killing queries?
Connection counts and process metadata help distinguish many idle clients from active or blocked work. Inspect first and correlate with the application’s connection pool and incident time. Ending a session can roll back transactions or interrupt users, so it should not be the first response to a high count.
Before you start
- An approved monitoring or administrative database session.
- Privileges appropriate for the metadata being inspected.
Instructions
1. Read the connection count
Compare the value with a normal baseline for this application and time of day. An isolated count does not establish a leak or capacity fault.
SHOW GLOBAL STATUS LIKE 'Threads_connected';Reads the current connection-count status variable.
2. Read a bounded metadata sample
The query omits statement text to reduce unnecessary exposure of customer data or credentials embedded in SQL. Sorting by duration highlights work or idle states that have persisted longest.
SELECT ID, USER, HOST, DB, COMMAND, TIME, STATE
FROM performance_schema.processlist
ORDER BY TIME DESC
LIMIT 20;Lists up to twenty process records available to the authorised account; visibility depends on privileges.
3. Correlate with the application
Distinguish sleeping pooled connections, long active statements and waiting states. Check whether the application closes connections and whether a database lock or downstream dependency explains the symptom. Preserve a small time-stamped sample before deciding on a targeted intervention.
Check the result
- The connection pattern is explained and any corrective action targets a specific application, statement or pool setting.
Troubleshooting
- The Performance Schema table is unavailable or access is denied
- Verify the server version and monitoring permissions. Use the database administrator’s supported process view; do not grant unrestricted application privileges as a workaround.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
