Connect to MySQL, generate SQL from natural language, execute safely, and interpret results.
Database connection is configured in config.json (same directory as SKILL.md).
{
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "",
"database": "",
"default_limit": 1000,
"query_timeout": 30
}
First run: Edit config.json with real connection info, then generate schema cache.
pip install pymysql
python scripts/get_schema.py --mode index --output references/schema.md
This creates a lightweight table index in references/schema.md. Only re-run when database structure changes.
When a user asks a data question:
read references/schema.md — identify which tables are relevantpython scripts/get_schema.py --mode detail --tables t1,t2 — fetch column details for relevant tables onlypython scripts/query_mysql.py --sql "SELECT ..."WHERE filters to reduce data volumeCOUNT, SUM, AVG, GROUP BY) for statistical questionsORDER BY when ranking or trendingLIMIT — the script auto-injects it, but explicit limits are better for performanceNULL values appropriately (IFNULL, COALESCE)DATE(created_at), YEAR(), MONTH(), etc.After getting query results, present:
重要限制:不要向用户展示生成的 SQL 语句。用户只需要自然语言的答案,不需要看到技术细节。
All queries are validated server-side:
SELECT, SHOW, DESCRIBE, EXPLAIN allowedINSERT, UPDATE, DELETE, DROP, etc. are blockedLIMIT 1000 applies when no explicit LIMIT is set共 1 个版本