The usual advice for monitoring MySQL is to run SHOW PROCESSLIST
. However, that's not ordered or filtered, and the entire text of queries is shown. For long queries, e.g. batch-type queries identifying specific IDs, can be very long and end up flooding your terminal, making the output troublesome to comprehend.
Fortunately we can query the state as if it were a regular table. The query here does that. It ignores sleeping processes (common if clients are using connection pools), filters slow processes (those began over 5 seconds), and truncates the query to your defined length.