agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/databases/mysql/SKILL.md

mysql

Skill15 starsChanged 42 days agoMITView on GitHub

Expert MySQL relational database assistance covering InnoDB engine, query optimization with EXPLAIN, transactions, and replication. Use when designing relational schemas, tuning SQL queries, or scaling MySQL.

10 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use keyset seek pagination utilizing indexed primary key comparisons:

    line 75
  2. Very specific:

    Use EXPLAIN FORMAT=JSON: Inspect query execution plans to identify temporary tables, filesorts, and full table scans.

    line 92
  3. Distinctive:

    Use random UUIDv4 as primary keys: Random UUIDs cause index page fragmentation and severe disk I/O thrashing during inserts.

    line 97
  4. Very specific:

    Use SELECT * in production code: Query only needed columns to leverage covering indexes.

    line 98

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

MySQL

MySQL is a widely used relational database management system (RDBMS). It is the "M" in the LAMP stack and powers huge platforms like Facebook and WordPress.

When to Use

  • Web Application Relational Backbone: The world's most popular open-source relational database powering WordPress, Rails, and web backends.
  • ACID Transaction Guarantees: Processing financial transactions, order checkouts, and inventory balances reliably with InnoDB.
  • Read-Heavy Web Applications: Scaling reads horizontally using primary-replica asynchronous and semi-synchronous replication topologies.
  • Modern Document Store (JSON Columns): Indexing and querying semi-structured JSON documents alongside relational SQL tables.

Quick Start

-- Upsert (Insert or Update)
INSERT INTO users (id, name) VALUES (1, 'Jane')
ON DUPLICATE KEY UPDATE name = 'Jane';

Core Concepts

InnoDB Storage Engine & B+Tree Clustered Indexes

InnoDB stores table rows clustered physically on disk by primary key, providing instant primary key lookups:

CREATE TABLE commerce.orders (
    order_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT UNSIGNED NOT NULL,
    total_amount DECIMAL(12, 2) NOT NULL,
    status ENUM('PENDING', 'PAID', 'SHIPPED', 'CANCELLED') DEFAULT 'PENDING',
    details JSON,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_user_status (user_id, status)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;

JSON Functional Indexes

Creates virtual indexed columns over specific JSON paths to accelerate document queries:

-- Create functional index on JSON path
ALTER TABLE commerce.orders
ADD INDEX idx_customer_tier ((CAST(details->>'$.customer.tier' AS CHAR(20))));

-- Optimized index query
SELECT * FROM commerce.orders
WHERE details->>'$.customer.tier' = 'Platinum';

Semi-Synchronous Replication Topology

Guarantees that at least one read replica has received transaction events before returning success:

[ Primary Master ] ──Replication Event──→ [ Replica 1 (Awaits ACK) ] ──ACK──→ [ Primary Commits ]
                                                  │
                                                  ▼
                                       [ Replica 2 (Async) ]

Common Patterns

Keyset Pagination (Seek Method)

Problem: Traditional OFFSET 1000000 LIMIT 20 scans and discards 1 million rows, resulting in extreme query latency.

Solution: Use keyset seek pagination utilizing indexed primary key comparisons:

-- Fast seek pagination regardless of page depth
SELECT id, title, price, created_at
FROM products
WHERE (created_at, id) < ('2025-03-01 10:00:00', 94821)
ORDER BY created_at DESC, id DESC
LIMIT 20;

Best Practices

Do:

  • Choose Compact Primary Keys: Use BIGINT UNSIGNED AUTO_INCREMENT or ordered UUIDs (v7); secondary indexes store the primary key.
  • Size innodb_buffer_pool_size Appropriately: Allocate 70-80% of total physical RAM to the InnoDB buffer pool on dedicated servers.
  • Use EXPLAIN FORMAT=JSON: Inspect query execution plans to identify temporary tables, filesorts, and full table scans.
  • Enable Binary Logging with Row Format: Set binlog_format = ROW for safe, deterministic replication and point-in-time recovery.

Don't:

  • Use random UUIDv4 as primary keys: Random UUIDs cause index page fragmentation and severe disk I/O thrashing during inserts.
  • Use SELECT * in production code: Query only needed columns to leverage covering indexes.
  • Store unstructured text without character sets: Default to utf8mb4 with utf8mb4_0900_ai_ci collation for full Unicode support.

Troubleshooting

ErrorCauseSolution
ERROR 1205 (HY000): Lock wait timeout exceededLong-running transaction holding row locks requested by another query.Kill blocking transaction (SHOW PROCESSLIST) and keep transactions short.
ERROR 1040: Too many connectionsConnection pool exhaustion exceeding max_connections.Increase max_connections or place ProxySQL connection pooler in front.
Using filesort; Using temporary in EXPLAINQuery cannot use index to satisfy ORDER BY or GROUP BY.Add composite index that includes both WHERE filter columns and ORDER BY columns in order.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.