Agent skill

Mysql Deadlock Analyzer

by openocta in openocta/openocta_skills

Full-chain MySQL deadlock analysis. An agent skill from openocta/openocta_skills.

MITAuto-check passedDatabases

Install Mysql Deadlock Analyzer

skills CLI
$ npx skills add openocta/openocta_skills --skill mysql-deadlock-analyzer -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install openocta/openocta_skills mysql-deadlock-analyzer --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/openocta/openocta_skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/mysql-deadlock-analyzer .claude/skills/mysql-deadlock-analyzer && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mysql-deadlock-analyzer
GitHub stars
166
Token cost
~2.2k tokens
SKILL.md length
414 words
Files
3
Skills in repo
8
Repo updated
First seen
Licence
MIT

At a glance

Full-chain MySQL deadlock analysis. An agent skill from openocta/openocta_skills.

  • Works in 5 steps: Capture Deadlock Status → Check Current Lock State (MySQL 5.7+) → Find Long Transactions → …
  • Databases work in your project
  • SKILL.md covers Overview, When to Use, Required MCP Server and Diagnostic Workflow, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Mysql Deadlock Analyzer is an agent skill from openocta/openocta_skills. Full-chain MySQL deadlock analysis. Captures InnoDB status, parses lock chains, identifies deadlock patterns (AB-BA / Gap Lock / FK), finds current lock waits and long transactions, outputs structured report with fix recommendations. Supports MySQL 5.7+ performanceschema and 5.6 compatibility mode.

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files (for example `README.md` and `mate.json`).

It sits in Databases. It works with MySQL. The repository describes itself as: 本仓库用于汇集第三方贡献的 OpenOcta 技能(Skill)资源,便于分享、版本管理与分发。 The licence is MIT.

When your agent uses it

  • Databases work in your project

Example prompts

  • “/mysql-deadlock-analyzer”

Requirements

  • Pre-approved tools (allowed-tools): db_query, db_get_status, db_get_processlist

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Capture Deadlock Status
  2. Check Current Lock State (MySQL 5.7+)
  3. Find Long Transactions
  4. Parse Deadlock Pattern
  5. Check Configuration

What it can do on your machine

Read from SKILL.md and the folder at commit 6ac4479. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • db_query
    • db_get_status
    • db_get_processlist

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql and bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Mysql Deadlock Analyzer loads about 2.2k tokens when it runs. Until then it costs about 81 tokens; SKILL.md has 414 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~81
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from openocta/openocta_skills at commit 6ac4479, republished under its MIT licence (© openocta). 414 words, ~2,157 tokens.

Download SKILL.mdSave it as .claude/skills/mysql-deadlock-analyzer/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
mysql-deadlock-analyzer
description
Full-chain MySQL deadlock analysis. Captures InnoDB status, parses lock chains, identifies deadlock patterns (AB-BA / Gap Lock / FK), finds current lock waits and long transactions, outputs structured report with fix recommendations. Supports MySQL 5.7+ performance_schema and 5.6 compatibility mode.
allowed-tools
db_query, db_get_status, db_get_processlist
version
1.0.0

MySQL Deadlock Analyzer

Overview

Deadlocks are among the most difficult database issues to diagnose — they involve multiple transactions, lock chains, and often intermittent patterns. This skill performs a full-chain deadlock analysis:

  1. Capture the latest deadlock from InnoDB status
  2. Parse lock chains (who holds what, who waits for what)
  3. Classify deadlock pattern (AB-BA mutual wait, Gap Lock, FK cascade, etc.)
  4. Check for current lock waits and long transactions
  5. Output a structured report with root cause and fix recommendations

When to Use

  • Deadlock alerts or errors from application logs (Error: 1213 Deadlock found)
  • Proactive monitoring shows Innodb_deadlocks counter increasing
  • Investigation of lock contention during peak hours
  • After schema changes that may affect locking behavior

Required MCP Server

ToolPurpose
db_queryRun diagnostic SQL queries
db_get_statusGet InnoDB deadlock counters
db_get_processlistCheck for blocking queries
Required MySQL Privileges
  • PROCESS — View all threads and InnoDB status

Diagnostic Workflow

Step 1: Capture Deadlock Status
sql
-- Get deadlock count and recent lock metrics
SHOW GLOBAL STATUS LIKE 'Innodb_deadlocks';
SHOW GLOBAL STATUS LIKE 'Innodb_row_lock_waits';
SHOW GLOBAL STATUS LIKE 'Innodb_row_lock_time_avg';

-- Capture full InnoDB status (contains LATEST DETECTED DEADLOCK section)
SHOW ENGINE INNODB STATUS;
Step 2: Check Current Lock State (MySQL 5.7+)
sql
-- Current lock waits (who is blocking whom)
SELECT
  waiting_trx.trx_id AS waiting_trx,
  blocking_trx.trx_id AS blocking_trx,
  waiting_trx.trx_state AS wait_state,
  waiting_trx.trx_started AS wait_started,
  waiting_trx.trx_query AS wait_query,
  blocking_trx.trx_query AS block_query
FROM information_schema.innodb_lock_waits w
JOIN information_schema.innodb_trx waiting_trx ON w.requesting_trx_id = waiting_trx.trx_id
JOIN information_schema.innodb_trx blocking_trx ON w.blocking_trx_id = blocking_trx.trx_id;

-- Fallback for MySQL 5.6:
SELECT * FROM information_schema.innodb_trx ORDER BY trx_started;
Step 3: Find Long Transactions
sql
-- Transactions running longer than 60 seconds
SELECT
  trx_id, trx_state, trx_started,
  TIMESTAMPDIFF(SECOND, trx_started, NOW()) AS duration_sec,
  trx_tables_locked, trx_rows_locked,
  LEFT(trx_query, 200) AS current_query
FROM information_schema.innodb_trx
WHERE TIMESTAMPDIFF(SECOND, trx_started, NOW()) > 60
ORDER BY trx_started;
Step 4: Parse Deadlock Pattern

From the InnoDB status output, extract and classify:

PatternDescriptionTypical Fix
AB-BATransaction A locks row1→row2, B locks row2→row1Ensure consistent access order
Gap LockNext-key lock on index gapReduce range scans, use RC isolation
FK CascadeForeign key triggers cascading lockAdd index on FK column
Auto-IncConcurrent inserts competing for auto-inc lockUse innodb_autoinc_lock_mode=2
Lock UpgradeS-lock upgraded to X-lockReduce transaction scope
Step 5: Check Configuration
sql
SHOW VARIABLES LIKE 'innodb_print_all_deadlocks';
SHOW VARIABLES LIKE 'tx_isolation';
SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';

Output Template

🔒 MySQL Deadlock Analysis Report
═════════════════════════════════
📋 Instance: {host}:{port}
   Analysis Time: {timestamp}

🔍 Deadlock Status
  Total Deadlocks: {count}
  Row Lock Waits: {count}
  Avg Lock Wait: {ms}ms

📜 Latest Deadlock (from InnoDB Status)
  ┌─────────────────────────────────────────┐
  │ Transaction A (ID: {trx_id})            │
  │   Status: {status}  Duration: {time}s   │
  │   Holds: {locks_held}                   │
  │   Waits: {locks_waited}                 │
  │   SQL: {sql_fragment}                   │
  ├─────────────────────────────────────────┤
  │ Transaction B (ID: {trx_id})            │
  │   Status: {status}  Duration: {time}s   │
  │   Holds: {locks_held}                   │
  │   Waits: {locks_waited}                 │
  │   SQL: {sql_fragment}                   │
  └─────────────────────────────────────────┘
  Pattern: {AB-BA / Gap Lock / FK / Auto-Inc}

⚠️ Current Lock Waits
  {If blocking chains exist, list them}

📊 Long Transactions ({count} found)
  | Trx ID | Duration | State | SQL |
  |--------|----------|-------|-----|

💡 Root Cause
  {Analysis conclusion}

🛠️ Recommendations
  1. {SQL-level fix} — e.g., add index, change access order
  2. {Code-level fix} — e.g., unify lock order, add retry
  3. {Config-level fix} — e.g., enable innodb_print_all_deadlocks
Show full SKILL.md (169 more words)Show less

Example Usage

User: "Check for deadlocks on db-prod-01"

AI Response:

🔒 Deadlock Analysis — db-prod-01:3306

Total Deadlocks: 0 ✅ (no deadlocks recorded)
Row Lock Waits: 0 ✅ (no lock contention)

Long Transactions: 3 found
  | Trx ID | Duration | State    | SQL |
  |--------|----------|----------|-----|
  | 5847M  | 0s       | RUNNING  | SELECT ... |
  | 5847K  | 0s       | RUNNING  | UPDATE ... |

💡 Conclusion: No current deadlock issues.
   Recommendation: Enable innodb_print_all_deadlocks = ON
   to capture future deadlock details automatically.

Best Practices

Prevention
  • Ensure consistent access order across transactions (always lock row1 before row2)
  • Keep transactions short — avoid user input inside transactions
  • Add appropriate indexes to avoid full table scans (which cause more locking)
  • Consider READ COMMITTED isolation level if Gap Locks are an issue
  • Enable innodb_print_all_deadlocks = ON for continuous monitoring
Configuration Recommendations
sql
-- Always enable this in production
SET GLOBAL innodb_print_all_deadlocks = ON;

-- Monitor lock wait timeout (default 50s)
SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';

-- For high-concurrency workloads
SET GLOBAL innodb_autoinc_lock_mode = 2;
Advanced: Deadlock Monitoring SQL (for Grafana / Alerts)
sql
-- Deadlock rate (deadlocks per minute)
SELECT
  VARIABLE_VALUE AS deadlocks,
  NOW() AS collected_at
FROM performance_schema.global_status
WHERE VARIABLE_NAME = 'Innodb_deadlocks';

-- Row lock contention rate
SELECT
  VARIABLE_VALUE AS lock_waits,
  NOW() AS collected_at
FROM performance_schema.global_status
WHERE VARIABLE_NAME = 'Innodb_row_lock_waits';

-- Average lock wait time (milliseconds)
SELECT
  ROUND(VARIABLE_VALUE / 1000, 2) AS avg_lock_wait_ms
FROM performance_schema.global_status
WHERE VARIABLE_NAME = 'Innodb_row_lock_time_avg';

Alert thresholds for monitoring:

MetricWarningCritical
Deadlocks/min> 1> 5
Row lock waits/min> 100> 500
Avg lock wait> 100ms> 500ms
Advanced: pt-deadlock-logger Integration

For continuous deadlock capture beyond innodb_print_all_deadlocks:

bash
# Percona Toolkit: capture deadlocks to a file
pt-deadlock-logger \
  --host={host} --port={port} \
  --user={user} --password={password} \
  --dest D=/tmp/deadlocks.log \
  --daemonize --interval 30

# Output format:
# server ts thread txn_id txn_time user host ip db tbl idx lock_type lock_mode wait_hold query
Advanced: Deadlock Replay with EXPLAIN

After identifying the deadlocked SQL, replay to verify the lock pattern:

sql
-- Check the execution plan of the deadlocked query
EXPLAIN FORMAT=JSON {deadlocked_sql};

-- Check if the query uses the correct index
SHOW INDEX FROM {table};

-- Verify row scan count vs actual data volume
SELECT COUNT(*) FROM {table} WHERE {where_clause};

Quick Reference

ActionQuery
Deadlock countSHOW STATUS LIKE 'Innodb_deadlocks'
InnoDB statusSHOW ENGINE INNODB STATUS
Current transactionsSELECT * FROM information_schema.innodb_trx
Lock waits (5.7+)SELECT * FROM performance_schema.data_lock_waits
Lock waits (5.6)SELECT * FROM information_schema.innodb_lock_waits
Enable deadlock loggingSET GLOBAL innodb_print_all_deadlocks = ON

Use this skill for comprehensive deadlock diagnosis — from detection to root cause to fix.

© openocta, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in mysql-deadlock-analyzer of openocta/openocta_skills.

  • SKILL.md
  • README.md
  • mate.json

Open the folder on GitHubat commit 6ac4479

Compare with similar skills

Mysql Deadlock Analyzer next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mysql Deadlock Analyzer compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mysql Deadlock Analyzer this skillopenocta/openocta_skills166—~2.2kAutomated safety check: PassMIT
Write Script Mysqlwindmill-labs/windmill18k—~2.2kAutomated safety check: PassCustom licence
Mysqlolasunkanmi-SE/codebuddy141—~399Automated safety check: PassMIT
How To Communicatedatabasus/databasus8.8k—~3.9kAutomated safety check: PassMIT
Tgf Server Devthkhxm/tgf128—~1.3kAutomated safety check: NotesMIT
DB Ops SopOpenDCAI/DataMind423—~388Automated safety check: PassApache-2.0

Similar skills

  • Write Script Mysql

    windmill-labs/windmill

    MUST use when writing MySQL queries.

    18k GitHub stars~2.2k tokensUpdated today
    DatabasesAuto-check passed
  • Mysql

    olasunkanmi-SE/codebuddy

    Manage MySQL databases via the mysql CLI. An agent skill from olasunkanmi-SE/codebuddy.

    141 GitHub stars~399 tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • How To Communicate

    databasus/databasus

    Communicate clearly in every response, progress update and agent-authored document.

    8.8k GitHub stars~3.9k tokensUpdated 15 days ago
    DatabasesAuto-check passed
  • Tgf Server Dev

    thkhxm/tgf

    基于 tgf v2(github.com/thkhxm/tgf/v2)用确定性的 tgfctl 工作流创建、验证和维护 Go 游戏服务器项目。

    128 GitHub stars~1.3k tokensUpdated 2 mo ago
    DatabasesAuto-check: notes
  • DB Ops Sop

    OpenDCAI/DataMind

    Database operations runbook — backup, recovery, performance tuning, troubleshooting.

    423 GitHub stars~388 tokensUpdated 18 days ago
    DatabasesAuto-check passed
  • Altimate Data Warehouse Delegate

    AltimateAI/data-engineering-skills

    Delegates dbt and warehouse tasks such as lineage, migrations and cost attribution to the altimate-code CLI agent and relays its answer back.

    128 GitHub stars~1.4k tokensUpdated 6 days ago
    DatabasesAuto-check passed

More from openocta/openocta_skills

All 8 skills in this repo
  • Mysql Full Inspection Skill

    openocta/openocta_skills

    对远程多实例MySQL数据库执行全方位深度巡检,覆盖基础健康、连接负载、性能慢查询、索引冗余、主从复制、容量空间、账号安全、配置风险八大维度,全自动完成巡检扫描、风险识别、问题定级、优化建议、报告归档与飞书推送,适用于生产/测试所有运行中MySQL实例常态化合规巡检。适用场景:用户要求进行 MySQL 全链路健康检查、MySQL 综合巡检、MySQL 风险扫描、MySQL 性能审计、MySQL…

    166 GitHub stars~2k tokensUpdated 3 mo ago
    Auto-check passed
  • Server Patrol

    openocta/openocta_skills

    Linux 与网络设备只读健康巡检;直接运行 scripts/patrol.sh,配置由平台侧信道注入,Agent 不读取环境变量

    166 GitHub stars~522 tokensUpdated 3 mo ago
    Auto-check passed
  • Wechat Gzh Analyzer

    openocta/openocta_skills

    分析微信公众号后台数据,包括文章阅读量、评论、点赞等统计。当用户需要分析微信公众号数据、导出公众号文章统计报表时调用此技能。

    166 GitHub stars~2.6k tokensUpdated 3 mo ago
    Auto-check passed
  • Mysql Replication Lag Resolver

    openocta/openocta_skills

    Replication lag root cause analysis with automated resolution workflow.

    166 GitHub stars~2.6k tokensUpdated 3 mo ago
    Auto-check passed
  • Mysql Slow Query Diagnose

    openocta/openocta_skills

    Slow query diagnosis with root cause analysis and index optimization recommendations.

    166 GitHub stars~2.7k tokensUpdated 3 mo ago
    Auto-check passed
  • Tidb Cluster Inspector

    openocta/openocta_skills

    Comprehensive TiDB cluster inspection. An agent skill from openocta/openocta_skills.

    166 GitHub stars~2.9k tokensUpdated 3 mo ago
    Auto-check passed

Works with

Categories

Questions about Mysql Deadlock Analyzer

What does Mysql Deadlock Analyzer do?

Full-chain MySQL deadlock analysis. An agent skill from openocta/openocta_skills. Mysql Deadlock Analyzer is an agent skill from openocta/openocta_skills. Full-chain MySQL deadlock analysis.

When should I use Mysql Deadlock Analyzer?

Mysql Deadlock Analyzer fits situations like: databases work in your project.

How do I install Mysql Deadlock Analyzer in Claude Code?

Run `npx skills add openocta/openocta_skills --skill mysql-deadlock-analyzer -a claude-code`. Or copy the skill folder (mysql-deadlock-analyzer in openocta/openocta_skills) into .claude/skills/mysql-deadlock-analyzer in your project. Claude Code loads it when a task matches its description.

How do I install Mysql Deadlock Analyzer in Codex?

Run `npx skills add openocta/openocta_skills --skill mysql-deadlock-analyzer -a codex`. Or copy the skill folder (mysql-deadlock-analyzer in openocta/openocta_skills) into .agents/skills/mysql-deadlock-analyzer in your project. Codex loads it when a task matches its description.

Can I use Mysql Deadlock Analyzer in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add openocta/openocta_skills --skill mysql-deadlock-analyzer -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mysql-deadlock-analyzer, .gemini/skills/mysql-deadlock-analyzer, .github/skills/mysql-deadlock-analyzer and .opencode/skills/mysql-deadlock-analyzer in your project.

What does Mysql Deadlock Analyzer need to run?

SKILL.md names no scripts, command-line tools or credentials: Mysql Deadlock Analyzer is instructions for the agent only. Its frontmatter pre-approves these tools: db_query, db_get_status, db_get_processlist.

Does Mysql Deadlock Analyzer access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Mysql Deadlock Analyzer safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mysql Deadlock Analyzer use?

Mysql Deadlock Analyzer is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mysql Deadlock Analyzer use?

About 2.2k tokens (SKILL.md is roughly 8.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Mysql Deadlock Analyzer?

Skills that share tags, products or a category with Mysql Deadlock Analyzer: Write Script Mysql (windmill-labs/windmill, 18k stars), Mysql (olasunkanmi-SE/codebuddy, 141 stars), How To Communicate (databasus/databasus, 8.8k stars) and Tgf Server Dev (thkhxm/tgf, 128 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mysql Deadlock Analyzer?

openocta (a GitHub user) maintains it in openocta/openocta_skills, which has 166 GitHub stars. The repository holds 8 skills in this directory. The repository was last updated on June 22, 2026.

Source: openocta/openocta_skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.