Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

mysql-expert

БесплатноБез исполняемых скриптовНе проверен

MySQL and MariaDB administration and development: InnoDB internals, indexing, query tuning, replication, and online schema change. Use when the user mentions…

personamanagmentlayerот personamanagmentlayer★ 46 звёзд на GitHub

Об этом скилле

MySQL Expert

MySQL differs from PostgreSQL in ways that matter for design, not just syntax: the clustered primary key, the storage-engine boundary, and a replication model built on the binary log.

Core Concepts

InnoDB Is the Database

Everything below assumes InnoDB. Rows are stored inside the primary key index — the table is the primary key B-tree. Three consequences drive most design decisions:

  1. The primary key is present in every secondary index, so a wide primary key inflates every index on the table.
  2. A secondary index lookup costs two traversals: the index, then the primary key. Unless the index covers the query.
  3. Inserts in primary key order are cheap; random primary keys cause page splits and fragmentation.

This is why a BIGINT AUTO_INCREMENT or a time-ordered UUID (UUIDv7) beats a random UUIDv4 primary key by a wide margin on large tables.

Character Sets

Use utf8mb4 and nothing else. MySQL's utf8 is a three-byte subset that cannot store emoji or some CJK characters, and it fails by truncating or erroring at insert time.

CREATE TABLE orders (…) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Collation determines comparison and sorting. utf8mb4_0900_ai_ci is accent-insensitive and case-insensitive; use utf8mb4_0900_as_cs or _bin when you need exact matching, for example on tokens or hashes.

Isolation and Locking

The default is REPEATABLE READ, which is stricter than PostgreSQL's default and uses gap locks that surprise people migrating across.

SELECT @@transaction_isolation;
SET SESSION transaction_isolation = 'READ-COMMITTED';   -- often the better default

READ COMMITTED reduces gap locking and deadlocks for typical OLTP workloads. Change it deliberately and test — it also changes replication semantics for statement-based binlog formats.

Schema Design

CREATE TABLE orders (
  id            BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  public_id     BINARY(16) NOT NULL,                    -- UUID stored compactly
  customer_id   BIGINT UNSIGNED NOT NULL,
  status        ENUM('pending','paid','shipped','cancelled') NOT NULL,
  total_minor   BIGINT NOT NULL,                        -- money as integer minor units
  currency      CHAR(3) NOT NULL,
  created_at    TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  PRIMARY KEY (id),
  UNIQUE KEY uk_orders_public_id (public_id),
  KEY idx_orders_customer_created (customer_id, created_at),
  CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Decisions worth defending:

  • Surrogate BIGINT primary key, with the externally visible identifier as a separate unique column. Keeps the clustered index narrow and sequential.
  • BINARY(16) for UUIDs, not CHAR(36): a quarter of the size, and it propagates into every secondary index.
  • Money as integer minor units. DECIMAL is acceptable; FLOAT and DOUBLE are not, ever.
  • TIMESTAMP in UTC, with fractional seconds where ordering matters. DATETIME does not carry a time zone conversion; be deliberate about which you want.
  • Explicit NOT NULL. MySQL is permissive by default; strict mode and NOT NULL catch problems at write time.

Verify strict mode is on — without it, MySQL silently truncates data:

SELECT @@sql_mode;  -- must include STRICT_TRANS_TABLES and NO_ENGINE_SUBSTITUTION

Indexing

The leftmost-prefix rule governs composite indexes: an index on (a, b, c) serves a, (a, b) and (a, b, c), but not b alone.

-- Covering index: the query never touches the table
ALTER TABLE orders ADD KEY idx_cover (customer_id, created_at, status, total_minor);

EXPLAIN SELECT status, total_minor FROM orders
WHERE customer_id = 42 ORDER BY created_at DESC LIMIT 20;
-- Extra: Using index    <- no lookup to the clustered index

Order composite index columns by: equality predicates first, then the range or sort column, then columns needed only for covering.

Things that silently disable an index:

WHERE DATE(created_at) = '2026-01-31'       -- function on the column
WHERE customer_id = '42'                    -- string compared to an integer column
WHERE name LIKE '%dupont'                   -- leading wildcard
WHERE status != 'paid'                      -- low selectivity negation

Rewrite the first as a range: created_at >= '2026-01-31' AND created_at < '2026-02-01'.

Read plans with EXPLAIN ANALYZE (MySQL 8.0.18+), which reports actual rows and time rather than estimates:

EXPLAIN ANALYZE SELECT … ;
EXPLAIN FORMAT=JSON SELECT … ;    -- cost details, used keys, filtering ratios

Finding Slow Queries

-- Enable capture
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 0.5;
SET GLOBAL log_queries_not_using_indexes = 'ON';

-- Or query performance_schema, which needs no log parsing
SELECT DIGEST_TEXT,
       COUNT_STA
Полный SKILL.md на GitHub

Установить mysql-expert в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Write
Edit
Bash(mysql:*, mysqldump:*, mysqladmin:*, docker:*, pt-online-schema-change:*)
Grep
Glob

Вложенные файлы

references/OPERATIONS.md

FAQ

Что делает скилл mysql-expert?

MySQL and MariaDB administration and development: InnoDB internals, indexing, query tuning, replication, and online schema change. Use when the user mentions MySQL, MariaDB, InnoDB, `my.cnf`, slow queries, `EXPLAIN`, binlog or replication lag, gtid, Percona or pt-online-schema-change, or when the task involves designing a MySQL schema, diagnosing lock contention, or migrating a large table without downtime.

Как установить скилл mysql-expert?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл mysql-expert запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить mysql-expert с