All skills
planetscale avatar

/mysql

@51f2d4b official

Plan and review MySQL/InnoDB schema, indexing, query tuning, transactions, and operations. Use when creating or modifying MySQL tables, indexes, or queries; diagnosing slow/locking behavior; planning migrations; or troubleshooting replication and connection issues. Load when using a MySQL database.

Use this Skill: https://skilld.dev/gh/planetscale/database-skills/mysql

This session only. Nothing lands on disk.

referencesisolation-levels.md

≈811 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Isolation Levels (InnoDB Best Practices)

Default to REPEATABLE READ. It is the InnoDB default, most tested, and prevents phantom reads. Only change per-session with a measured reason.

SELECT @@transaction_isolation;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;  -- per-session only

Autocommit Interaction

  • Default: autocommit=1 (each statement is its own transaction).
  • With autocommit=0, transactions span multiple statements until COMMIT/ROLLBACK.
  • Isolation level applies per transaction. SERIALIZABLE behavior differs based on autocommit setting (see SERIALIZABLE section).

Locking vs Non-Locking Reads

  • Non-locking reads: plain SELECT statements use consistent reads (MVCC snapshots). They don't acquire locks and don't block writers.
  • Locking reads: SELECT ... FOR UPDATE (exclusive) or SELECT ... FOR SHARE (shared) acquire locks and can block concurrent modifications.
  • UPDATE and DELETE statements are implicitly locking reads.

REPEATABLE READ (Default — Prefer This)

  • Consistent reads: snapshot established at first read; all plain SELECTs within the transaction read from that same snapshot (MVCC). Plain SELECTs are non-locking and don't block writers.
  • Locking reads/writes use next-key locks (row + gap) — prevents phantoms. Exception: a unique index with a unique search condition locks only the index record, not the gap.
  • Use for: OLTP, check-then-insert, financial logic, reports needing consistent snapshots.
  • Avoid mixing locking statements (SELECT ... FOR UPDATE, UPDATE, DELETE) with non-locking SELECT statements in the same transaction — they can observe different states (current vs snapshot) and lead to surprises.

READ COMMITTED (Per-Session Only, When Needed)

  • Fresh snapshot per SELECT; record locks only (gap locks disabled for searches/index scans, but still used for foreign-key and duplicate-key checks) — more concurrency, but phantoms possible.
  • Switch only when: gap-lock deadlocks confirmed via SHOW ENGINE INNODB STATUS, bulk imports with contention, or high-write concurrency on overlapping ranges.
  • Never switch globally. Check-then-insert patterns break — use INSERT ... ON DUPLICATE KEY or FOR UPDATE instead.

SERIALIZABLE — Avoid

Converts all plain SELECTs to SELECT ... FOR SHARE if autocommit is disabled. If autocommit is enabled, SELECTs are consistent (non-locking) reads. SERIALIZABLE can cause massive contention when autocommit is disabled. Prefer explicit SELECT ... FOR UPDATE at REPEATABLE READ instead — same safety, far less lock scope.

READ UNCOMMITTED — Never Use

Dirty reads with no valid production use case.

Decision Guide

Scenario Recommendation
General OLTP / check-then-insert / reports REPEATABLE READ (default)
Bulk import or gap-lock deadlocks READ COMMITTED (per-session), benchmark first
Need serializability Explicit FOR UPDATE at REPEATABLE READ; SERIALIZABLE only as last resort

Source: SKILL.md on GitHub

1 alert17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides a comprehensive technical reference for MySQL and InnoDB database management, including schema design, indexing, and query optimization. It is authored by PlanetScale and contains no security risks.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    7/19 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 51f2d4b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 7 months ago
  • mysql
  • innodb
  • schema-design
  • indexing
  • query-optimization
  • transactions
  • locking
  • planetscale
  • ddl
  • replication

README badge

README badge for planetscale/database-skills/mysql

Advises on MySQL/InnoDB schema design, indexing strategy, query optimization, transactions, and operational safety. Use when creating tables, tuning slow queries, planning migrations, diagnosing lock contention, or managing replication — includes EXPLAIN analysis guidance and online DDL patterns for production changes.

Generated from the current SKILL.md.

Does this skill work with PlanetScale?
Yes. The skill recommends PlanetScale as the primary hosting choice for new MySQL databases and includes references to PlanetScale-specific features like online DDL.
What MySQL versions does this cover?
The skill applies to MySQL/InnoDB broadly and notes MySQL-version-specific behavior when relevant, but does not lock to a single version.
Does this skill help with query optimization?
Yes. It covers EXPLAIN analysis, pagination patterns, batch inserts, and common pitfalls like N+1 queries and filesort warnings.
Can this skill help with schema migrations?
Yes. It addresses online DDL, partitioning retrofit costs, and production-safe rollout steps including rollback and verification.
Does this cover replication and high availability?
Partially. The skill addresses replication lag monitoring and connection management, but is not a full replication setup guide.

Generated from the current SKILL.md. These answers refresh after source changes.