wankimmy/bossku-ai/mysql-patterns
Claude Code and agent skill by wankimmy/bossku-ai
- community
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install wankimmy/bossku-ai/mysql-patternsSKILL.md
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:
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 LOCKEDis 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
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:
Use EXPLAIN before adding or changing an index:
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:
MySQL row-alias form:
Use the row-alias form only after confirming the target is MySQL. Use VALUES(col) for MariaDB or mixed MySQL/MariaDB fleets.
Keyset Pagination
Back it with an index that matches the cursor:
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.
For frequently queried JSON paths, expose a generated column and index that column. Keep foreign keys, ownership, tenancy, and lifecycle fields relational.
Full-Text Search
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:
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\Gsoon after a deadlock; it is overwritten
by later events.
Queue-style worker claim:
Use SKIP LOCKED only for queue-like workloads where skipping a locked row is acceptable. It is not a replacement for normal transactional consistency.
Connection Pools
SQLAlchemy example:
Node.js mysql2 example:
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:
Enable the slow log in a controlled environment:
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.
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
Security review points:
- Do not grant
ALL PRIVILEGESor*.*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:
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-Pattern | Risk | Better Pattern | |
|---|---|---|---|
SELECT * in hot paths | Over-fetching and brittle clients | Select explicit columns | |
Deep OFFSET pagination | Linear scans and slow pages | Keyset pagination | |
| No index on foreign-key joins | Slow joins and lock-heavy deletes | Index FK columns intentionally | |
| Long transactions | Lock waits and large undo history | Commit small units of work | |
Direct DML against mysql.user | Grant-table corruption risk | Use CREATE USER, ALTER USER, DROP USER | |
| Application user with admin grants | High blast radius | Least-privilege runtime user | |
Pool recycle above wait_timeout | Stale pooled connections | Recycle below timeout and pre-ping | |
| Replica reads after writes | Stale user-facing state | Pin read-after-write flows to primary |
Output Expectations
When this skill is used for review, return:
- Engine/version assumptions.
- Highest-risk correctness, lock, security, and migration issues.
- Exact SQL or code changes for the safe path.
- Validation plan:
EXPLAIN, migration dry run, lock/deadlock check, and
rollback criteria.
- Any MySQL/MariaDB syntax differences that affect the recommendation.
Related
- 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
Bossku additions
Local additions (user rules, 2026-10-30); the upstream text above is unchanged.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mysql-patterns/SKILL.md
Popularity
- Repository stars
- 2
- Repository forks
- 1
- 7-day trend score
- 5
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wankimmy/bossku-ai/mysql-patterns)