{"skill":{"slug":"mysql-query-assistant","displayName":"MySQL Natural Language Query Assistant","summary":"translate natural-language analytics requests into mysql queries, connect to a live mysql database, inspect schema and column comments, execute read-only sql...","description":"---\nname: mysql-query-assistant\ndescription: translate natural-language analytics requests into mysql queries, connect to a live mysql database, inspect schema and column comments, execute read-only sql, and validate query correctness against real results. use when chatgpt needs to work with mysql through direct connection details provided by environment variables, especially for ad hoc analysis, sql generation, schema discovery, query debugging, or cautious database workflows that must verify results before presenting them. also use for restricted write workflows that first generate a preview select and never auto-execute the write statement.\n---\n\n# Mysql Query Assistant\n\nUse this skill to turn a user's request into safe MySQL work against a live database.\n\n## Core workflow\n\nFor every request, follow this sequence:\n\n1. Inspect connection prerequisites from `references/connection-and-safety.md`.\n2. Discover relevant schema first. Prefer column comments when available.\n3. Draft the SQL.\n4. Execute only read-only SQL with `scripts/run_read_query.py`.\n5. Perform double validation:\n   - structural validation: tables, columns, joins, filters, grouping, and syntax match the request.\n   - result validation: returned rows and aggregates look semantically consistent with the user's intent.\n6. If validation fails, revise the SQL and run it again.\n7. Present the final answer using the output template below.\n\n## Default behavior\n\n- Prefer `SELECT` queries only.\n- Never auto-execute `INSERT`, `UPDATE`, `DELETE`, `REPLACE`, `ALTER`, `DROP`, `TRUNCATE`, `CREATE`, `GRANT`, or `REVOKE`.\n- Keep result samples small by default.\n- When the request is ambiguous, use schema inspection to narrow candidate tables before writing SQL.\n- Prefer explicit column lists over `SELECT *` unless schema exploration is the user's goal.\n- Prefer bounded queries. Add `LIMIT` when the user did not ask for a full extract.\n\n## Schema discovery workflow\n\nBefore generating SQL, inspect schema with `scripts/introspect_schema.py`.\n\nUse this order:\n\n1. List candidate tables.\n2. Inspect columns, data types, keys, and column comments for the most relevant tables.\n3. Infer business meaning from comments and names.\n4. Only then draft SQL.\n\nIf comments are missing, fall back to table names, column names, keys, and a few small probing queries.\n\n## Read-only execution workflow\n\nUse `scripts/run_read_query.py` to execute the SQL.\n\nThe script rejects non-read-only statements. It also blocks multi-statement execution.\n\nWhen verifying a query:\n\n1. Run the first candidate SQL.\n2. Review row count, sample rows, and whether the columns answer the request.\n3. If the result is empty or suspicious, explain why and try a corrected query when appropriate.\n4. If multiple interpretations are plausible, prefer the query best supported by schema and results, and say what assumption you made.\n\n## Restricted write workflow\n\nWhen the user asks for a write operation:\n\n1. Do not execute the write statement.\n2. First produce a preview `SELECT` that shows exactly which rows would be affected.\n3. Then produce the write SQL separately.\n4. Clearly label the write SQL as not executed.\n5. Call out any missing safety condition such as a weak or absent `WHERE` clause.\n\n## Output template\n\nUse this structure unless the user asks for a different format.\n\n### Final SQL\n\n```sql\n[final sql]\n```\n\n### Validation\n\n- Structural check: [why the sql shape matches the request]\n- Result check: [why the returned data seems correct, or why confidence is limited]\n\n### Sample results\n\nShow 5 to 20 rows when available and useful. Keep wide tables compact.\n\n### Result summary\n\nProvide a brief natural-language summary of what the query shows.\n\n### Notes\n\nInclude assumptions, caveats, and any schema uncertainties.\n\n## Execution details\n\n- Use environment variables described in `references/connection-and-safety.md`.\n- Use `scripts/introspect_schema.py` for schema discovery.\n- Use `scripts/run_read_query.py` for executing read-only SQL.\n- If the python mysql driver is missing, install one of the documented options before running the scripts.\n\n## Examples\n\n### Example: analytics request\n\nUser request: `统计最近 7 天每天新增用户数`\n\nExpected approach:\n\n1. Inspect likely user table and created-at column.\n2. Confirm time column semantics from comments or names.\n3. Generate grouped date query.\n4. Run it.\n5. Verify the date buckets and counts look plausible.\n\n### Example: restricted write request\n\nUser request: `把 status = 'pending' 且 30 天前创建的订单改成 expired`\n\nExpected approach:\n\n1. Generate preview `SELECT` for the target rows.\n2. Generate `UPDATE` SQL separately.\n3. Do not execute the `UPDATE`.\n4. Warn if the table lacks a reliable key or if the filter looks too broad.\n","topics":["MySQL","Database","Debugging","SQL"],"tags":{"database":"1.0.0","latest":"1.0.0","mysql":"1.0.0"},"stats":{"comments":0,"downloads":417,"installsAllTime":16,"installsCurrent":0,"stars":1,"versions":1},"createdAt":1777548545013,"updatedAt":1778492809868},"latestVersion":{"version":"1.0.0","createdAt":1777548545013,"changelog":"Initial release of mysql-query-assistant\n\n- Translates natural-language analytics requests into MySQL queries.\n- Connects to a live MySQL database for schema inspection and read-only SQL execution.\n- Validates SQL correctness both structurally and via real query results.\n- Supports a read-only workflow by default; restricted write requests generate preview SELECT statements and SQL, but never auto-execute writes.\n- Prioritizes schema discovery before query writing, including use of column comments and types.\n- Presents outputs using a standard template with SQL, validation, sample results, and notes.","license":"MIT-0"},"metadata":null,"owner":{"handle":"nocb","userId":"s176c3n8td6m29gmtxkemsz0b585tgbq","displayName":"hansen","image":"https://avatars.githubusercontent.com/u/1073133?v=4"},"moderation":null}