skills/mysql/SKILL.md
Use when writing MySQL or MariaDB SQL, editing MySQL-flavored .sql files, using mysql CLI, mysqldump, connection strings, InnoDB settings, replication, stored procedures, JSON, or query tuning.
npx skillsauth add cofin/flow mysqlInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
MySQL is the world's most popular open-source relational database, powering applications from small web apps to large-scale internet services. This skill covers MySQL 8.0+ (and MariaDB where noted).
# Python (PyMySQL) -- always parameterized, always utf8mb4
import pymysql
conn = pymysql.connect(
host="localhost",
user="app_user",
password="secret",
database="mydb",
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor,
)
with conn:
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM users WHERE id = %s", (42,))
user = cursor.fetchone()
conn.commit()
-- CTE (8.0+)
WITH active_users AS (
SELECT id, name FROM users WHERE status = 'active'
)
SELECT au.name, COUNT(o.id) AS order_count
FROM active_users au
JOIN orders o ON o.user_id = au.id
GROUP BY au.name;
-- Window function
SELECT customer_id, order_date, total,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) AS rn
FROM orders;
-- Upsert
INSERT INTO counters (key_name, value)
VALUES ('page_views', 1)
ON DUPLICATE KEY UPDATE value = value + VALUES(value);
UUID_TO_BIN(UUID(), 1) for ordered UUIDs in MySQL 8.0+.Choose InnoDB (always). Use AUTO_INCREMENT integer PKs unless UUIDs are required (then use ordered UUID v7). Set CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci at the database and table level.
Use parameterized queries in application code -- never string interpolation. Use CTEs for readability. Use window functions instead of self-joins for ranking/running totals.
Create indexes to support WHERE, JOIN, and ORDER BY clauses. Use composite indexes following the leftmost-prefix rule. Check coverage with EXPLAIN.
Run EXPLAIN ANALYZE on slow queries. Check the slow query log (long_query_time = 1). Tune buffer pool size, redo log size, and innodb_flush_log_at_trx_commit for the workload.
Confirm query plans use indexes (no unexpected full table scans). Verify utf8mb4 encoding. Test with realistic data volumes.
%s placeholders (Python) or ? (Node/Java).charset=utf8mb4 in connections and CHARACTER SET utf8mb4 in DDL. Plain utf8 is a 3-byte subset that cannot store emoji or some CJK characters.UUID_TO_BIN(UUID(), 1) for ordered storage.Before delivering MySQL code, verify:
Task: Parameterized query with index creation for an orders lookup.
-- Create table with proper encoding and engine
CREATE TABLE orders (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
status ENUM('pending', 'shipped', 'delivered', 'cancelled') NOT NULL DEFAULT 'pending',
total DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_orders_user_status (user_id, status),
INDEX idx_orders_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Verify index usage
EXPLAIN SELECT id, total, created_at
FROM orders
WHERE user_id = 42
AND status = 'shipped'
ORDER BY created_at DESC
LIMIT 20;
# Application code -- parameterized query
async def get_user_orders(conn, user_id: int, status: str) -> list[dict]:
async with conn.cursor() as cursor:
await cursor.execute(
"SELECT id, total, created_at FROM orders "
"WHERE user_id = %s AND status = %s "
"ORDER BY created_at DESC LIMIT 20",
(user_id, status),
)
return await cursor.fetchall()
</example>
For detailed guides and code examples, refer to the following documents in references/:
testing
Use when syncing Beads state to markdown, checking Flow status, refreshing context docs, validating task markers, or reporting ready/blocked Flow work.
testing
Use when initializing Flow in a repo, configuring .agents, installing or checking Beads bd, setting local-only sync policy, or creating first project context files.
data-ai
Use when drafting PRDs, researching, planning, refining, revising, or creating .agents/specs/<flow_id>/spec.md worksheets for Flow.
testing
Use when implementing Flow tasks from Beads or spec.md, claiming ready work, applying TDD, recording task notes, committing, and syncing after task state changes.