Skip to content

Instantly share code, notes, and snippets.

@sqlstunts
Created January 22, 2016 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sqlstunts/2e3a53f5adea4429f3e4 to your computer and use it in GitHub Desktop.
Save sqlstunts/2e3a53f5adea4429f3e4 to your computer and use it in GitHub Desktop.
Get live queries from MySQL instance in real time.
SELECT
plist.id, plist.user, plist.host, plist.db,
plist.command, plist.TIME, plist.state,
plist.info, trx.trx_state,
trx.trx_wait_started,
trx.trx_query, blockerw.blocking_trx_id,
(CASE
WHEN (blockerw.blocking_trx_id IS NOT NULL) THEN 'Blocked'
WHEN (lockedtr.trx_id IS NOT NULL) THEN 'Locked'
ELSE ''
END) is_blocker
FROM
information_schema.PROCESSLIST AS plist
LEFT OUTER JOIN
information_schema.innodb_trx AS trx ON trx.Trx_MySQL_Thread_ID = plist.id
LEFT OUTER JOIN
information_schema.innodb_lock_waits blockerw ON blockerw.blocking_trx_id = trx.trx_id
LEFT OUTER JOIN
information_schema.innodb_lock_waits lockedw ON lockedw.requesting_trx_id = trx.trx_id
LEFT OUTER JOIN
information_schema.innodb_trx lockedtr ON lockedtr.trx_id = lockedw.blocking_trx_id
where plist.command NOT IN ('Sleep', 'Binlog Dump')
ORDER BY time DESC
LIMIT 10;
SELECT id, user, host, db, command, time, state, info
FROM information_schema.processlist
WHERE command NOT IN ('Sleep', 'Binlog Dump')
ORDER BY time ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment