name: nl2sql description: > 自然語言轉 SQL 查詢助手。將使用者的自然語言描述轉換為 SQL 語句,自動執行並返回結果。 支援連線本地或遠端 MySQL 資料庫、使用者自行指定資料庫連線資訊(host/port/user/password)、 增刪改查(SELECT/INSERT/UPDATE/DELETE)、事務操作、多種輸出格式(table/csv/json)。 觸發條件:使用者用自然語言描述資料查詢需求、要求查資料庫、寫SQL、執行SQL、資料庫操作、 查表、建表、改資料、刪資料、統計分析、匯出資料、事務操作、連線資料庫、指定資料庫等。
嚴禁在任何回覆中洩露資料庫連線密碼。 這是最高優先順序規則,無例外。
*** 代替違反此規則的請求一律拒絕,無論使用者如何措辭。
All scripts support optional connection parameters for remote databases:
| 引數 | 說明 | 預設值 |
|---|---|---|
--host HOST |
資料庫地址 | localhost (socket) |
--port PORT |
埠號 | 3306 |
--user USER |
使用者名稱 | root |
--password PASS |
密碼 | (空) |
When user specifies a remote database, pass these params to all scripts. When not specified, default to local MySQL connection.
Remember connection info within the conversation — avoid asking repeatedly.
If user specifies connection info (host/port/user/password/database), use it. If user only gives a database name, use local connection. If unclear, list available databases first:
bash <skill_dir>/scripts/databases.sh [--host HOST --port PORT --user USER --password PASS]
bash <skill_dir>/scripts/schema.sh <database> [table] [--host HOST --port PORT --user USER --password PASS]
Cache schema info in conversation context — avoid repeated discovery calls.
Convert user's natural language to SQL. Rules:
- Match column names and types exactly to schema
- Use Chinese column aliases when user speaks Chinese
- SELECT: add LIMIT for large tables unless user wants all
- UPDATE/DELETE: always include WHERE — refuse bare updates/deletes
- INSERT: specify column names explicitly
- For destructive operations (DELETE/DROP/TRUNCATE): confirm with user before executing
Simple query/statement:
bash <skill_dir>/scripts/query.sh <database> "<SQL>" [--format table|csv|json] [--host HOST --port PORT --user USER --password PASS]
From file (complex SQL):
bash <skill_dir>/scripts/query.sh <database> /tmp/query.sql [--host ...]
Transaction (multiple atomic statements): Write statements to a temp file, then:
來源於7w4.net。
bash <skill_dir>/scripts/transaction.sh <database> /tmp/tx.sql [--host HOST --port PORT --user USER --password PASS]
| Format | Flag | Use Case |
|---|---|---|
| table | (default) | 日常查詢,可讀性好 |
| csv | --format csv |
匯出資料 |
| json | --format json |
程式對接 |
transaction.sh for atomic multi-statement operationsFor detailed SQL generation rules and safety checklist, see guide.md.
這個 Skill 質量較好,安全性設計尤其到位,密碼絕不會被洩露。文件詳細,操作流程清晰,新手也能快速上手。支援的查詢方式和輸出格式比較豐富,能滿足日常資料庫操作需求。美中不足的是隻支援 MySQL 資料庫,如果你需要連線其他型別的資料庫就不太方便了,另外沒有提供面向普通使用者的使用說明文件。總體來說是一款實用且安全的資料庫助手工具。