
Mysql Patterns
Apply production-grade MySQL and MariaDB schema, indexing, upsert, queue, and pool patterns with correct version-specific syntax checks.
Overview
MySQL Patterns is an agent skill most often used in Build (also Ship review, Operate errors) that supplies production MySQL and MariaDB schema, query, indexing, and pool patterns with version-aware syntax.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill mysql-patternsWhat is this skill?
- Activation checklist for schema, migrations, slow queries, locks, pools, replicas
- Requires VERSION() and version_comment before MySQL vs MariaDB divergent syntax
- Covers keyset pagination, upserts, full-text, JSON columns, and queue-style SKIP LOCKED usage
- Documents ON DUPLICATE KEY UPDATE differences: MySQL row aliases vs MariaDB VALUES(col)
Adoption & trust: 1.2k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are shipping on MySQL or MariaDB but risk wrong upsert syntax, bad indexes, or queue queries that deadlock or skip rows inconsistently.
Who is it for?
Indie backend builders maintaining real MySQL/MariaDB data layers who need opinionated production patterns during implementation and review.
Skip if: Greenfield projects on Postgres-only stacks, analytics warehouses, or beginners who only need SELECT tutorials.
When should I use this skill?
Designing MySQL or MariaDB tables, reviewing migrations, debugging slow queries, deadlocks, pools, replicas, or applying version-specific upsert and queue patterns.
What do I get? / Deliverables
Your agent applies version-checked SQL patterns for migrations, pagination, upserts, and pools aligned to the detected engine.
- Version-checked SQL patterns
- Migration review notes
- Index and pool configuration guidance
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Database design and query fixes are core Build backend work before the API ships. MySQL/MariaDB patterns target persistence layers, migrations, and connection behavior on the backend shelf.
Where it fits
Design indexes and upsert statements after running VERSION() on a staging MariaDB instance.
Have the agent review a migration that alters a large table before it hits production.
Debug connection pool exhaustion and lock waits using the skill's activation triggers for production incidents.
How it compares
Pattern library for relational ops on MySQL family engines, not an ORM codegen skill or hosted DB MCP.
Common Questions / FAQ
Who is mysql-patterns for?
Solo developers and small teams building SaaS or API backends on MySQL or MariaDB who want agent-guided production database habits.
When should I use mysql-patterns?
At Build → backend for schema and queries; at Ship → review before large migrations ship; at Operate → errors when investigating slow logs, locks, or pool exhaustion.
Is mysql-patterns safe to install?
It guides SQL and config changes that can affect production data—review the Security Audits panel on this page and never run destructive migrations without backups.
SKILL.md
READMESKILL.md - Mysql Patterns
# MySQL Patterns Use this skill when working on MySQL or MariaDB schema design, migrations, slow-query investigation, queue-style transactions, connection pools, or production database configuration. Prefer exact version checks before applying a feature-specific pattern because MySQL and MariaDB have diverged in several SQL details. ## Activation - Designing MySQL or MariaDB tables, indexes, and constraints - Reviewing migrations before they run on large production tables - Debugging slow queries, lock waits, deadlocks, or connection exhaustion - Adding keyset pagination, upserts, full-text search, JSON columns, or queues - Configuring application connection pools, read replicas, TLS, or slow logs ## Version Check Start by identifying the engine and version: ```sql SELECT VERSION(); SHOW VARIABLES LIKE 'version_comment'; ``` Keep MySQL and MariaDB guidance separate when syntax differs: - MySQL documents row aliases as the replacement for `VALUES(col)` in `ON DUPLICATE KEY UPDATE`; `VALUES(col)` is deprecated there. - MariaDB documents `VALUES(col)` as the supported way to reference inserted values in `ON DUPLICATE KEY UPDATE`; use it for cross-engine compatibility. - `SKIP LOCKED` is appropriate for queue-like work only. It skips locked rows and can return an inconsistent view, so do not use it for general accounting or integrity-sensitive reads. ## Schema Defaults ```sql CREATE TABLE orders ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, account_id BIGINT UNSIGNED NOT NULL, status VARCHAR(32) NOT NULL, total DECIMAL(15, 2) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, deleted_at DATETIME NULL, PRIMARY KEY (id), KEY idx_orders_account_status_created (account_id, status, created_at), KEY idx_orders_active (account_id, deleted_at) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ``` Default choices: | Use Case | Prefer | Avoid | | --- | --- | --- | | Surrogate primary keys | `BIGINT UNSIGNED AUTO_INCREMENT` | `INT` for tables that can grow beyond 2B rows | | UUID lookup keys | `BINARY(16)` with conversion helpers | `VARCHAR(36)` primary keys on hot tables | | Money and exact quantities | `DECIMAL(p, s)` | `FLOAT` or `DOUBLE` | | User-facing text | `utf8mb4` tables and indexes | MySQL `utf8` / `utf8mb3` defaults | | Application timestamps | `DATETIME` with UTC managed by the app | Assuming `DATETIME` stores time zone metadata | | Soft deletes | `deleted_at DATETIME NULL` plus scoped indexes | Filtering soft-deleted rows without an index | | Extensible status values | lookup table or constrained `VARCHAR` | `ENUM` when values change often | ## Indexing Composite index order usually follows equality predicates first, then range or sort columns: ```sql CREATE INDEX idx_orders_account_status_created ON orders (account_id, status, created_at); SELECT id, total FROM orders WHERE account_id = ? AND status = 'pending' AND created_at >= ? ORDER BY created_at DESC LIMIT 50; ``` Use `EXPLAIN` before adding or changing an index: ```sql EXPLAIN SELECT id, total FROM orders WHERE account_id = 123 AND status = 'pending' ORDER BY created_at DESC LIMIT 50; ``` Signals to investigate: | Field | Risk Signal | | --- | --- | | `type` | `ALL` on a large table | | `key` | `NULL` when a selective predicate exists | | `rows` | Very high row estimate for an interactive path | | `Extra` | `Using temporary`, `Using filesort`, or broad `Using where` | Avoid adding indexes blindly. Each index increases write cost, migration time, backup size, and buffer-pool pressure. ## Query Patterns ### Upsert Cross-engine-compatible form: ```sql INSERT INTO user_settings (user_id, setting_key, setti