Mysql query

From hashgraph-online/awesome-codex-plugins · View interactive version

Mysql query is an AI agent skill from the GitHub repository hashgraph-online/awesome-codex-plugins. Connect to MySQL and run read-only queries to inspect table data. Use when the user wants to query MySQL, show tables, view table contents, check schema, or run read-only SQL. Connection info must be provided by the user; do not read from environment or application config.

How to use this skill

Skill file

MySQL 连接与查询

何时使用

连接信息:必须由用户提供

执行合同

适用前提

任务变量

变量来源

执行入口

  1. 先确认 SQL 是只读语句,并按需补 LIMIT。
  2. 优先使用当前 skill 的脚本执行,除非用户明确要求别的方式。
  3. 若连接信息不完整或只读边界不清晰,先停在 待确认项,不要私自补全。
  4. 不把密码写入仓库、脚本文件或长期日志。

输出回落

执行查询

使用脚本(推荐)

使用 python3,依赖:pip3 install pymysql。路径示例:<skill_dir>/scripts/query.py,其中 <skill_dir> 为当前安装环境里的 mysql-query 技能目录。

参数(均由用户提供):

# 用户提供连接信息后,按下列方式调用
python3 <skill_dir>/scripts/query.py \
  --host 127.0.0.1 \
  --port 3306 \
  --user myuser \
  --password '用户提供的密码' \
  --database mydb \
  --sql "SELECT * FROM users LIMIT 10"

# 从标准输入传 SQL
echo "SELECT id, name FROM products LIMIT 5" | python3 <skill_dir>/scripts/query.py \
  --host 127.0.0.1 --port 3306 --user myuser --password 'xxx' --database mydb

脚本会:

内联代码时

若在项目内写一次性脚本,连接参数也必须来自用户当次提供的变量或输入,不要从 application.yml 或 os.environ 读取。

import pymysql

# 使用用户提供的变量(例如从 API 入参、用户输入传入)
host = user_provided_host
port = user_provided_port
user = user_provided_user
password = user_provided_password
database = user_provided_database

conn = pymysql.connect(host=host, port=port, user=user, password=password, database=database, charset="utf8mb4")
# ...

安全与约定

常见场景

| 用户需求 | 做法 |

|--------------------|------|

| 看某张表前 N 条 | SELECT * FROM table_name LIMIT 20 |

| 查表结构 | DESCRIBE table_name 或 SHOW CREATE TABLE table_name |

| 统计行数 | SELECT COUNT(*) FROM table_name |

| 按条件查 | 用 WHERE,必要时加 LIMIT |


Overview

连接 MySQL 执行只读查询,支持查看表列表、表结构、表数据和聚合统计。连接信息(host/port/user/password/database)必须由用户在本次对话中提供,禁止从配置文件或环境变量读取。

本 skill 只执行只读 SQL,不执行 INSERT / UPDATE / DELETE 等写操作。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.