当前位置: 首页 > Skill >

MySQL Natural Language Query Assistant

MySQL Natural Language Query Assistant

1.0.0 2026.11.27 浏览:438
获取Skill文件查看使用说明
作者:叶景许可证:
本文目录展开

Mysql Query Assistant

Use this skill to turn a user's request into safe MySQL work against a live database.

Core workflow

For every request, follow this sequence:

  1. Inspect connection prerequisites from references/connection-and-safety.md.
  2. Discover relevant schema first. Prefer column comments when available.
  3. Draft the SQL.
  4. Execute only read-only SQL with scripts/run_read_query.py.
  5. Perform double validation:
    • structural validation: tables, columns, joins, filters, grouping, and syntax match the request.
    • result validation: returned rows and aggregates look semantically consistent with the user's intent.
  6. If validation fails, revise the SQL and run it again.
  7. Present the final answer using the output template below.

Default behavior

  • Prefer SELECT queries only.
  • Never auto-execute INSERT, UPDATE, DELETE, REPLACE, ALTER, DROP, TRUNCATE, CREATE, GRANT, or REVOKE.
  • Keep result samples small by default.
  • When the request is ambiguous, use schema inspection to narrow candidate tables before writing SQL.
  • Prefer explicit column lists over SELECT * unless schema exploration is the user's goal.
  • Prefer bounded queries. Add LIMIT when the user did not ask for a full extract.

Schema discovery workflow

Before generating SQL, inspect schema with scripts/introspect_schema.py.

Use this order:

  1. List candidate tables.
  2. Inspect columns, data types, keys, and column comments for the most relevant tables.
  3. Infer business meaning from comments and names.
  4. Only then draft SQL.

If comments are missing, fall back to table names, column names, keys, and a few small probing queries.

Read-only execution workflow

Use scripts/run_read_query.py to execute the SQL.

The script rejects non-read-only statements. It also blocks multi-statement execution.

When verifying a query:

  1. Run the first candidate SQL.
  2. Review row count, sample rows, and whether the columns answer the request.
  3. If the result is empty or suspicious, explain why and try a corrected query when appropriate.
  4. If multiple interpretations are plausible, prefer the query best supported by schema and results, and say what assumption you made.

Restricted write workflow

When the user asks for a write operation:

  1. Do not execute the write statement.
  2. First produce a preview SELECT that shows exactly which rows would be affected.
  3. Then produce the write SQL separately.
  4. Clearly label the write SQL as not executed.
  5. Call out any missing safety condition such as a weak or absent WHERE clause.

Output template

Use this structure unless the user asks for a different format.

Final SQL

[final sql]

Validation

  • Structural check: [why the sql shape matches the request]
  • Result check: [why the returned data seems correct, or why confidence is limited]

Sample results

Show 5 to 20 rows when available and useful. Keep wide tables compact.

Result summary

Provide a brief natural-language summary of what the query shows.

Notes

Include assumptions, caveats, and any schema uncertainties.

Execution details

  • Use environment variables described in references/connection-and-safety.md.
  • Use scripts/introspect_schema.py for schema discovery.
  • Use scripts/run_read_query.py for executing read-only SQL.
  • If the python mysql driver is missing, install one of the documented options before running the scripts.

Examples

Example: analytics request

User request: 统计最近 7 天每天新增用户数

Expected approach:

  1. Inspect likely user table and created-at column.
  2. Confirm time column semantics from comments or names.
  3. Generate grouped date query.
  4. Run it.
  5. Verify the date buckets and counts look plausible.

Example: restricted write request

User request: 把 status = 'pending' 且 30 天前创建的订单改成 expired

Expected approach:

  1. Generate preview SELECT for the target rows.
  2. Generate UPDATE SQL separately.
  3. Do not execute the UPDATE.
  4. Warn if the table lacks a reliable key or if the filter looks too broad.

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,031
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,029
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,017
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,014
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,011
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,011
Skill 文件
  • SKILL.md
    • Mysql Query Assistant
    • Core workflow
    • Default behavior
    • Schema discovery workflow
    • Read-only execution workflow
    • Restricted write workflow
    • Output template
      • Final SQL
      • Validation
      • Sample results
      • Result summary
      • Notes
    • Execution details
    • Examples
      • Example: analytics request
      • Example: restricted write request
  • 项目或源文件

相关 Skill

更多
Volcengine RDS Mysql Volcengine RDS Mysql 使用火山引擎 RDS MySQL MCP Server,帮助用户完成 RDS MySQL 相关的实例管理、数据库操作、账号管理和运维任务,可直接调用 uv run ./scripts/call_rds_mysql.py 脚本获取实时结果。
Aliyun Adb Mysql Aliyun Adb Mysql 用于通过 OpenAPI/SDK 管理阿里云 AnalyticDB for MySQL (ADB),包括资源生命周期及配置操作。
MYSQL QUERY MYSQL QUERY 自动管理SSH隧道,查询项目数据库。适用于在已配置的数据库上执行SQL查询,尤其是需要通过SSH访问的数据库。
MySQL to PostgreSQL Migration MySQL to PostgreSQL Migration 在将项目数据库层从MySQL迁移到PostgreSQL时使用此技能。覆盖SQL方言转换(MyBatis XML/原始SQL)和ORM配置等...
在使用 Skeema 进行危险的数据库部署之前,将 MySQL 架构变更作为文件系统管理的 SQL 进行差异对比和审查 在使用 Skeema 进行危险的数据库部署之前,将 MySQL 架构变更作为文件系统管理的 SQL 进行差异对比和审查 将实时MySQL模式拉取到文件中,检查差异,并使用可重复的工作流程推送已审核的更改。