Skip to content

Instantly share code, notes, and snippets.

@bluerabbit
Last active February 20, 2024 04:43
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 bluerabbit/62afd8a3e0f60aac6b4f5f1581102fe3 to your computer and use it in GitHub Desktop.
Save bluerabbit/62afd8a3e0f60aac6b4f5f1581102fe3 to your computer and use it in GitHub Desktop.
MySQLでプロセスリストから遅いクエリのセッションをKILLするSQLを生成するSQL
SELECT
  *,
  CONCAT(CONCAT('KILL ', id), ';') AS KILL_SQL,
  CONCAT(CONCAT('CALL mysql.rds_kill(', id), ');') AS KILL_SQL_FOR_RDS
FROM
  INFORMATION_SCHEMA.PROCESSLIST
WHERE
  db = 'your_db'
  AND info LIKE '%probrem_query%'
  AND user = 'your_user'
  AND host LIKE '%your_host%'
  AND command LIKE 'Query'
  AND time > 10 -- sec
  AND id <> CONNECTION_ID()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment