/mysql:mysqlfrom mysql
Diagnoses and changes MySQL and MariaDB by measurement: EXPLAIN risk signals, composite indexes, upsert syntax differences, keyset pagination, InnoDB lock waits and deadlocks, SKIP LOCKED queues, online DDL, replica lag, pools and grants. Use for slow queries, deadlocks, lock stalls, or MySQL-specific SQL and schema defaults.
Ships in mysql. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Not for PostgreSQL (postgres), portable schema modeling or migration staging (db-schema-design), or caches and queues on Redis (redis), each if installed.
Make a measured MySQL or MariaDB change or investigation. Establish the workload and failure mode before changing SQL, indexes, schema, or config. Prefer the smallest reversible change that improves an observed outcome.
For portable tables, keys, constraints, and migration staging, use db-schema-design. MySQL and MariaDB have diverged in syntax and features, so never assume which engine or version runs, or that you have production access. Verify on the target, and check that version's manual. The sources for this skill are the MySQL 8.4 manual and the MariaDB documentation. MySQL 8.4 and 9.7 are the LTS lines, and 8.0 reached end of life in April 2026 (Oracle Sustaining Support only), so flag an 8.0 target for upgrade; check Oracle's MySQL support notices for current status. It was not run against a live MySQL server.
SELECT VERSION(); and SHOW VARIABLES LIKE 'version_comment';. Note managed-service limits, replicas, a proxy or pooler, and whether the target is production.KILL, and load-generating probes against production only with authorization and a recovery plan.performance_schema, or SHOW FULL PROCESSLIST for evidence.log_queries_not_using_indexes is noisy, so enable it only for a bounded window.EXPLAIN ANALYZE executes the statement. Run it only where that is safe, and wrap writes in a transaction you roll back.Start with EXPLAIN. Compare the estimate with reality for the real parameters.
| Field | Risk signal |
|---|---|
type | ALL (full scan) on a large table |
key | NULL when a selective predicate exists |
rows | A very high estimate on an interactive path |
Extra | Using temporary, Using filesort, or a broad Using where |
A full scan is wrong only when its actual cost misses the completion condition. Rank a few falsifiable causes (missing or unusable index, non-sargable predicate, stale statistics, wide rows, lock waits) and change one variable per probe.
Indexes. Order composite keys by equality predicates first, then a range or sort column. Add an index only for a named query, since each one adds write cost, backup size, and buffer-pool pressure. A function applied to an indexed column defeats the index.
Keyset pagination. Deep OFFSET scans and discards rows. Page with a stable cursor and an index that matches it:
SELECT id, name, created_at FROM products
WHERE (created_at, id) < (?, ?)
ORDER BY created_at DESC, id DESC
LIMIT 50;
-- backed by: CREATE INDEX idx_products_created_id ON products (created_at, id);
Upsert. MySQL 8.4 deprecates VALUES(col) inside ON DUPLICATE KEY UPDATE and documents a row alias instead. MariaDB documents VALUES(col), so don't assume it accepts a row alias. Pick the syntax from the engine you confirmed. On a table with more than one unique index, the update may match a different row than you expect, so avoid ON DUPLICATE KEY UPDATE there.
-- MySQL: row alias
INSERT INTO user_settings (user_id, setting_key, setting_value)
VALUES (?, ?, ?) AS new
ON DUPLICATE KEY UPDATE setting_value = new.setting_value;
-- MariaDB, or a mixed fleet: VALUES()
INSERT INTO user_settings (user_id, setting_key, setting_value)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value);
JSON. Keep keys, ownership, and lifecycle fields relational. For a hot JSON path, add a generated column and index that column.
Full-text. Built-in FULLTEXT with MATCH ... AGAINST covers simple relevance search. Move to a search engine for typo tolerance, faceting, or language-specific analysis.
Keep transactions short, make external calls before opening one, and lock rows in a consistent order. Index the predicates of UPDATE, DELETE, and locking reads so they lock fewer index records.
Always be ready to retry a transaction after a deadlock (error 1213) or lock-wait timeout. Retry the whole transaction with a bounded budget.
SHOW ENGINE INNODB STATUS reports only the most recent deadlock, so capture it soon after one occurs. innodb_print_all_deadlocks logs every deadlock to the error log. Turn it off when finished.
For locking reads, READ COMMITTED often reduces lock conflicts. Don't change isolation to hide a race.
Queue claim. SKIP LOCKED lets workers claim different rows without waiting. The manual notes that skipping locked rows returns an inconsistent view, so use it only for queue-like tables, and give stuck work a recovery policy. It is unsafe for statement-based replication.
START TRANSACTION;
SELECT id FROM jobs WHERE status = 'pending' ORDER BY created_at LIMIT 1 FOR UPDATE SKIP LOCKED;
UPDATE jobs SET status = 'processing', started_at = CURRENT_TIMESTAMP WHERE id = ?;
COMMIT;
Follow the existing schema's conventions first. For new tables:
| Need | Prefer | Avoid |
|---|---|---|
| Surrogate key | BIGINT UNSIGNED AUTO_INCREMENT | INT on tables that may pass 2 billion rows |
| UUID key | BINARY(16) with conversion helpers | VARCHAR(36) primary keys on hot tables |
| Money, exact quantities | DECIMAL(p, s) | FLOAT, DOUBLE |
| User text | utf8mb4 for tables and indexes | utf8mb3, which can't store 4-byte characters |
| Application timestamps | DATETIME, with UTC set by the application | Assuming DATETIME stores a zone |
| Status values that change | Lookup table, or VARCHAR with a CHECK where the version enforces it | ENUM for values that change often |
Soft deletes (deleted_at) need an index that includes the column, or every query filters by scan. InnoDB clusters rows by primary key, so a long or random primary key enlarges every secondary index.
ALTER TABLE runs before running it on a large table, and read references/online-ddl.md for the algorithm, lock, and metadata-lock rules.SHOW REPLICA STATUS on current MySQL and on MariaDB, which accepts SLAVE or REPLICA. Older MySQL versions use SHOW SLAVE STATUS.wait_timeout closes them, and enable a liveness check (a ping on checkout) to survive failover and network drops. Size the pool from the workload and the server's max_connections across all clients.SELECT, INSERT, UPDATE, DELETE. Keep migration and admin accounts separate from the runtime account. Require TLS when traffic crosses hosts, and keep credentials in the platform's secret manager, never in examples or repository files. Create and change users with CREATE USER and ALTER USER, not direct writes to the grant tables.unit-testing).What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub adminhead/claude-plugins --plugin mysql