Agent skill

Mysql Patterns

by affaan-m in affaan-m/ECC

MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends.

MITAuto-check passedDatabases

Install Mysql Patterns

skills CLI
$ npx skills add affaan-m/ECC --skill mysql-patterns -a claude-code

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

GitHub CLI
$ gh skill install affaan-m/ECC mysql-patterns --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/affaan-m/ECC.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/mysql-patterns .claude/skills/mysql-patterns && 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-patterns
GitHub stars
277k
Used in
2 other repos
Token cost
~3k tokens
SKILL.md length
972 words
Files
1
Skills in repo
683
Repo updated
First seen
Licence
MIT

At a glance

MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends.

  • Works in 5 steps: Engine/version assumptions. → Highest-risk correctness, lock,… → Exact SQL or code changes for the safe… → …
  • Designing MySQL
  • SKILL.md covers Activation, Version Check, Schema Defaults and Indexing, plus 10 more sections
  • Needs DB_PASSWORD

What it does

Mysql Patterns is an agent skill from affaan-m/ECC. MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends. Use when designing MySQL or MariaDB schemas and indexes, or when a query, transaction, or replica lags.

Its SKILL.md is about 3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases. It works with MySQL and MariaDB. The repository describes itself as: The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond. The licence is MIT.

When your agent uses it

  • Designing MySQL
  • MariaDB schemas and indexes

Example prompts

  • “/mysql-patterns”

Requirements

  • Python 3
  • Node.js

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Engine/version assumptions.
  2. Highest-risk correctness, lock, security, and migration issues.
  3. Exact SQL or code changes for the safe path.
  4. Validation plan: EXPLAIN, migration dry run, lock/deadlock check, and
  5. Any MySQL/MariaDB syntax differences that affect the recommendation.

What it can do on your machine

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

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    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, python, javascript and ini).

    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 these keys or tokens, usually read from environment variables:

    • DB_PASSWORD

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

Context cost

Mysql Patterns loads about 3k tokens when it runs. Until then it costs about 60 tokens; SKILL.md has 972 words of instructions outside code blocks.

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

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 affaan-m/ECC at commit 2d515e4, republished under its MIT licence (© affaan-m). 972 words, ~3,043 tokens.

Download SKILL.mdSave it as .claude/skills/mysql-patterns/SKILL.md (or your agent's skills folder).
name
mysql-patterns
description
MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends. Use when designing MySQL or MariaDB schemas and indexes, or when a query, transaction, or replica lags.
metadata.origin
ECC

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 CasePreferAvoid
Surrogate primary keysBIGINT UNSIGNED AUTO_INCREMENTINT for tables that can grow beyond 2B rows
UUID lookup keysBINARY(16) with conversion helpersVARCHAR(36) primary keys on hot tables
Money and exact quantitiesDECIMAL(p, s)FLOAT or DOUBLE
User-facing textutf8mb4 tables and indexesMySQL utf8 / utf8mb3 defaults
Application timestampsDATETIME with UTC managed by the appAssuming DATETIME stores time zone metadata
Soft deletesdeleted_at DATETIME NULL plus scoped indexesFiltering soft-deleted rows without an index
Extensible status valueslookup table or constrained VARCHARENUM 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:

FieldRisk Signal
typeALL on a large table
keyNULL when a selective predicate exists
rowsVery high row estimate for an interactive path
ExtraUsing 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, setting_value)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE
    setting_value = VALUES(setting_value),
    updated_at = CURRENT_TIMESTAMP;

MySQL row-alias form:

sql
INSERT INTO user_settings (user_id, setting_key, setting_value)
VALUES (?, ?, ?) AS new
ON DUPLICATE KEY UPDATE
    setting_value = new.setting_value,
    updated_at = CURRENT_TIMESTAMP;

Use the row-alias form only after confirming the target is MySQL. Use VALUES(col) for MariaDB or mixed MySQL/MariaDB fleets.

Keyset Pagination
sql
SELECT id, name, created_at
FROM products
WHERE (created_at, id) < (?, ?)
ORDER BY created_at DESC, id DESC
LIMIT 50;

Back it with an index that matches the cursor:

sql
CREATE INDEX idx_products_created_id ON products (created_at, id);

Do not use deep OFFSET pagination on large tables; it makes the server scan and discard rows before returning the page.

JSON Fields

Use JSON columns for extension data, not for fields that need heavy relational filtering or constraints.

sql
CREATE TABLE events (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    payload JSON NOT NULL,
    event_type VARCHAR(64)
        GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(payload, '$.type'))) STORED,
    KEY idx_events_type (event_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

For frequently queried JSON paths, expose a generated column and index that column. Keep foreign keys, ownership, tenancy, and lifecycle fields relational.

sql
ALTER TABLE articles ADD FULLTEXT KEY ft_articles_title_body (title, body);

SELECT id, title, MATCH(title, body) AGAINST (? IN NATURAL LANGUAGE MODE) AS score
FROM articles
WHERE MATCH(title, body) AGAINST (? IN NATURAL LANGUAGE MODE)
ORDER BY score DESC
LIMIT 20;

Use external search when you need typo tolerance, complex ranking, cross-table facets, or language-specific analysis beyond built-in full-text behavior.

Transactions

Keep transactions short and lock rows in a consistent order:

sql
START TRANSACTION;

SELECT id, balance
FROM accounts
WHERE id IN (?, ?)
ORDER BY id
FOR UPDATE;

UPDATE accounts SET balance = balance - ? WHERE id = ?;
UPDATE accounts SET balance = balance + ? WHERE id = ?;

COMMIT;

Deadlock and lock-wait checklist:

  • Lock rows in a deterministic order across code paths.
  • Do external API calls before opening the transaction, not inside it.
  • Add indexes for predicates used in UPDATE, DELETE, and locking reads.
  • On deadlock, roll back and retry the whole transaction with a bounded retry budget.
  • Capture SHOW ENGINE INNODB STATUS\G soon after a deadlock; it is overwritten by later events.

Queue-style worker claim:

sql
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;

Use SKIP LOCKED only for queue-like workloads where skipping a locked row is acceptable. It is not a replacement for normal transactional consistency.

Show full SKILL.md (403 more words)Show less

Connection Pools

SQLAlchemy example:

python
from sqlalchemy import create_engine

engine = create_engine(
    "mysql+mysqlconnector://app:secret@db.internal/app",
    pool_size=10,
    max_overflow=5,
    pool_timeout=30,
    pool_recycle=240,
    pool_pre_ping=True,
    connect_args={"connect_timeout": 5},
)

Node.js mysql2 example:

javascript
import mysql from 'mysql2/promise';

const pool = mysql.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
  enableKeepAlive: true,
  keepAliveInitialDelay: 30000,
});

const [rows] = await pool.execute(
  'SELECT id, total FROM orders WHERE account_id = ? LIMIT 50',
  [accountId],
);

Keep application pool recycling below the server wait_timeout. If the server uses wait_timeout = 300, a pool_recycle around 240 seconds is coherent; pool_pre_ping still helps recover from network and failover events.

Diagnostics

Useful first-pass commands:

sql
SHOW FULL PROCESSLIST;
SHOW ENGINE INNODB STATUS\G;
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'long_query_time';

Enable the slow log in a controlled environment:

sql
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;
SET GLOBAL log_queries_not_using_indexes = 'ON';

Use EXPLAIN ANALYZE only when it is safe to execute the query. It runs the statement and can be expensive on production-sized data.

Replication

Read replicas can lag. Do not route read-your-own-write paths, checkout flows, permission checks, or idempotency-key reads to a replica immediately after a write.

sql
-- MySQL legacy terminology, still common in existing fleets
SHOW SLAVE STATUS\G;

-- Newer terminology where supported
SHOW REPLICA STATUS\G;

Check the engine/version before standardizing on one command. Monitor replica SQL thread health, IO thread health, and lag, not just whether the TCP connection is alive.

Security

sql
CREATE USER 'app'@'%' IDENTIFIED BY 'use-a-secret-manager';
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'app'@'%';

ALTER USER 'app'@'%' REQUIRE SSL;

SELECT user, host
FROM mysql.user
WHERE user = '';

DROP USER IF EXISTS ''@'localhost';
DROP USER IF EXISTS ''@'%';

Security review points:

  • Do not grant ALL PRIVILEGES or *.* to application users.
  • Require TLS for application users when traffic crosses hosts or networks.
  • Store credentials in the platform secret manager, not in examples, scripts, or repository files.
  • Separate migration/admin users from runtime application users.
  • Audit public network exposure and bind addresses before tuning performance.

Configuration

Example starting point for a dedicated database host:

ini
[mysqld]
innodb_buffer_pool_size = 4G
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1

max_connections = 300
thread_cache_size = 50

wait_timeout = 300
interactive_timeout = 300
innodb_lock_wait_timeout = 10

slow_query_log = ON
long_query_time = 1
log_queries_not_using_indexes = ON

log_bin = mysql-bin
binlog_format = ROW
binlog_expire_logs_seconds = 604800

Treat configuration values as a prompt for review, not a universal preset. Size memory, connections, log retention, and durability settings from workload, hardware, backup policy, and recovery objectives.

Anti-Patterns

Anti-PatternRiskBetter Pattern
SELECT * in hot pathsOver-fetching and brittle clientsSelect explicit columns
Deep OFFSET paginationLinear scans and slow pagesKeyset pagination
No index on foreign-key joinsSlow joins and lock-heavy deletesIndex FK columns intentionally
Long transactionsLock waits and large undo historyCommit small units of work
Direct DML against mysql.userGrant-table corruption riskUse CREATE USER, ALTER USER, DROP USER
Application user with admin grantsHigh blast radiusLeast-privilege runtime user
Pool recycle above wait_timeoutStale pooled connectionsRecycle below timeout and pre-ping
Replica reads after writesStale user-facing statePin read-after-write flows to primary

Output Expectations

When this skill is used for review, return:

  1. Engine/version assumptions.
  2. Highest-risk correctness, lock, security, and migration issues.
  3. Exact SQL or code changes for the safe path.
  4. Validation plan: EXPLAIN, migration dry run, lock/deadlock check, and rollback criteria.
  5. Any MySQL/MariaDB syntax differences that affect the recommendation.
  • Skill: postgres-patterns - PostgreSQL-specific schema and query patterns
  • Skill: database-migrations - migration planning and rollout safety
  • Skill: backend-patterns - API and service-layer patterns
  • Skill: security-review - secret handling, auth, and least privilege
  • Agent: database-reviewer - broader database review workflow

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

Files

Just SKILL.md in skills/mysql-patterns of affaan-m/ECC.

Open the folder on GitHubat commit 2d515e4

Used in 2 other repositories

We found 3 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 2 other GitHub owners. This page covers the copy in affaan-m/ECC, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Mysql Patterns 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 Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mysql Patterns this skillaffaan-m/ECC277k2 repos~3kAutomated safety check: PassMIT
How To Communicatedatabasus/databasus8.9k—~3.9kAutomated safety check: PassMIT
Uql Ormrogerpadilla/uql125—~4.4kAutomated safety check: PassMIT
Golang Databaseunxed/f42442 repos~2.9kAutomated safety check: PassMIT
MySQL and MariaDB Query Toolevolution-foundation/evo-nexus545—~1.9kAutomated safety check: NotesCustom licence
Whodbxiaoyuge886/aigc198—~894Automated safety check: PassMIT

Similar skills

  • How To Communicate

    databasus/databasus

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

    8.9k GitHub stars~3.9k tokensUpdated today
    DatabasesAuto-check passed
  • Uql Orm

    rogerpadilla/uql

    Write code with UQL (the uql-orm package), the TypeScript ORM whose queries are plain JSON objects, on PostgreSQL, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, MongoDB, Turso, Neon, D1 and PGlite.

    125 GitHub stars~4.4k tokensUpdated today
    DatabasesAuto-check passed
  • Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context…

    244 GitHub starsUsed in 2 repos~2.9k tokens
    DatabasesAuto-check passed
  • MySQL and MariaDB Query Tool

    evolution-foundation/evo-nexus

    Queries MySQL or MariaDB databases declared in .env by label, read-only by default unless a connection explicitly allows writes.

    545 GitHub stars~1.9k tokensUpdated 5 mo ago
    DatabasesAuto-check: notes
  • Whodb

    xiaoyuge886/aigc

    Database operations including querying, schema exploration, and data analysis.

    198 GitHub stars~894 tokensUpdated 2 mo ago
    DatabasesAuto-check passed
  • Mysql

    sickn33/agentic-awesome-skills

    Administer MySQL/MariaDB databases. An agent skill from sickn33/agentic-awesome-skills.

    47k GitHub starsUsed in 2 repos~2.7k tokens
    DatabasesAuto-check: notes

More from affaan-m/ECC

All 682 skills in this repo
  • Skill Stocktake

    affaan-m/ECC

    Audits your installed Claude skills and commands for quality, with a quick mode for recently changed skills and a full mode that evaluates all of them through subagents.

    277k GitHub starsUsed in 5 repos~3.1k tokens
    Auto-check passed
  • Ingests, indexes, searches, edits and monitors video, audio and live streams through the VideoDB Python SDK, returning stream links, clips and timestamps.

    277k GitHub starsUsed in 3 repos~3.5k tokens
    Auto-check: notes
  • Docs Governance

    affaan-m/ECC

    Route broad documentation-governance requests to existing ECC skills and run an opt-in, read-only audit of mapped documentation roles, links, ADR indexes, and evidence references.

    277k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Rules Distillation

    affaan-m/ECC

    Scans installed skills for principles that recur across them and proposes rule-file changes: append, revise, add a section, create a file or leave as covered.

    277k GitHub starsUsed in 2 repos~2.3k tokens
    Auto-check passed
  • Builds DRAFT counterparty agreements from one markdown template and a small JSON spec per party, with clauses picked by the party's role.

    277k GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Set an ECC-specific frontend design direction for production UI work.

    277k GitHub starsUsed in 1 repo~2.2k tokens
    Auto-check passed

Works with

Categories

Questions about Mysql Patterns

What does Mysql Patterns do?

MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends. Mysql Patterns is an agent skill from affaan-m/ECC. MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends.

When should I use Mysql Patterns?

Mysql Patterns fits situations like: designing MySQL; mariaDB schemas and indexes.

How do I install Mysql Patterns in Claude Code?

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

How do I install Mysql Patterns in Codex?

Run `npx skills add affaan-m/ECC --skill mysql-patterns -a codex`. Or copy the skill folder (skills/mysql-patterns in affaan-m/ECC) into .agents/skills/mysql-patterns in your project. Codex loads it when a task matches its description.

Can I use Mysql Patterns 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 affaan-m/ECC --skill mysql-patterns -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-patterns, .gemini/skills/mysql-patterns, .github/skills/mysql-patterns and .opencode/skills/mysql-patterns in your project.

What does Mysql Patterns need to run?

Going by SKILL.md and its folder, Mysql Patterns needs credentials named DB_PASSWORD. Our summary lists: Python 3; Node.js.

Does Mysql Patterns 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 Patterns 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 Patterns use?

Mysql Patterns 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 Patterns use?

About 3k tokens (SKILL.md is roughly 12k 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 Patterns?

Skills that share tags, products or a category with Mysql Patterns: How To Communicate (databasus/databasus, 8.9k stars), Uql Orm (rogerpadilla/uql, 125 stars), Golang Database (unxed/f4, 244 stars) and MySQL and MariaDB Query Tool (evolution-foundation/evo-nexus, 545 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mysql Patterns?

affaan-m (a GitHub user) maintains it in affaan-m/ECC, which has 276,673 GitHub stars. The repository holds 683 skills in this directory. The repository was last updated on October 11, 2026.

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