zenixp

MYSQL QUERY

开发编程v1.0.1
作者:zenixp更新于 2026-05-18共 2 个版本 · 最新版本发布于 2026-03-03db-query@clawhub_zenixp/db-query
脚本工具#Database

据 AlphaMoat 统计,截至 2026-10,MYSQL QUERY 累计下载 6,587 次、获 9 个星标,按累计下载量在本次参与排名的 5,109 个 AI 技能中排名第 2,012 位,在「开发编程」分类(560 个)中排名第 212 位。

列表默认按累计下载量排序,也可按星标排序;详情页排名按累计下载量计算。

累计下载
6,587
星标
9
全站下载量排名
#2,012
全站前 40% · 「开发编程」前 38%
平台累计下载星标评论
ClawHub ↗4,6618-
SkillHub ↗6,5879—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

自动管理SSH隧道,查询项目数据库。适用于在已配置的数据库上执行SQL查询,尤其是需要通过SSH访问的数据库。

月度数据趋势

累计下载6,587
3,6155,2116,8072026-05 · 累计下载 3,8352026-06 · 累计下载 3,9982026-07 · 累计下载 4,2672026-08 · 累计下载 4,3852026-09 · 累计下载 4,8222026-10 · 累计下载 6,58726-0526-0926-10
星标9
8992026-05 · 星标 92026-06 · 星标 82026-07 · 星标 92026-08 · 星标 92026-09 · 星标 92026-10 · 星标 926-0526-0926-10

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-106,587—9
2026-094,822—9
2026-084,385+2.8%9
2026-074,267+6.7%9
2026-063,998+4.3%8
2026-053,835—9

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

3.9 KB · ClawHub v1.0.1
---
name: db-query
description: Query project databases with automatic SSH tunnel management. Use when you need to execute SQL queries against configured databases, especially those accessible only via SSH tunnels. Automatically manages SSH connection lifecycle (establishes tunnel before query, closes after). Supports multiple databases distinguished by description/name from config file.
---

# Database Query

## Overview

Query databases through a centralized configuration file with automatic SSH tunnel management. Handles connection details, SSH tunnel setup/teardown, and query execution.
展开全部(共 133 行)

## Security

**Passwords are never exposed in process lists.** The skill uses environment variables for credentials:
- `MYSQL_PWD` for database passwords (passed to mysql client)
- `SSHPASS` for SSH tunnel passwords (passed to sshpass)

**Recommended:** Store credentials in environment variables instead of the config file for better security.

## Configuration

### Setup

1. **Create config file** at `~/.config/clawdbot/db-config.json`:
   ```bash
   mkdir -p ~/.config/clawdbot
   # Copy example config and edit
   cp /usr/lib/node_modules/clawdbot/skills/db-query/scripts/config.example.json ~/.config/clawdbot/db-config.json
   ```

2. **Add database entries** with these fields:
   - `name`: Description used to find the database (required)
   - `host`: Database host (required)
   - `port`: Database port (default: 3306)
   - `database`: Database name (required)
   - `user`: Database user (required)
   - `password`: Database password (optional, can use env var)
   - `ssh_tunnel`: Optional SSH tunnel configuration

3. **SSH tunnel configuration** (if needed):
   - `enabled`: true/false
   - `ssh_host`: Remote SSH host
   - `ssh_user`: SSH username
   - `ssh_port`: SSH port (default: 22)
   - `local_port`: Local port to forward (e.g., 3307)
   - `remote_host`: Remote database host behind SSH (default: localhost)
   - `remote_port`: Remote database port (default: 3306)

### Environment Variables (Recommended)

Instead of storing passwords in the config file, use environment variables:

```bash
# Format: DB_PASSWORD_<DATABASE_NAME> (spaces replaced with underscores, uppercase)
export DB_PASSWORD_PRODUCTION_USER_DB="your_db_password"

# Format: SSH_PASSWORD_<DATABASE_NAME> for SSH tunnel password
export SSH_PASSWORD_PRODUCTION_USER_DB="your_ssh_password"
```

### Example Config

```json
{
  "databases": [
    {
      "name": "Production User DB",
      "host": "localhost",
      "port": 3306,
      "database": "user_db",
      "user": "db_user",
      "password": "",
      "ssh_tunnel": {
        "enabled": true,
        "ssh_host": "prod.example.com",
        "ssh_user": "deploy",
        "local_port": 3307
      }
    }
  ]
}
```

Set environment variables (recommended):
```bash
export DB_PASSWORD_PRODUCTION_USER_DB="your_db_password"
export SSH_PASSWORD_PRODUCTION_USER_DB="your_ssh_password"
```

## Usage

### List Databases

```bash
python3 /usr/lib/node_modules/clawdbot/skills/db-query/scripts/db_query.py --list
```

### Query a Database

```bash
python3 /usr/lib/node_modules/clawdbot/skills/db-query/scripts/db_query.py \
  --database "Production User DB" \
  --query "SELECT * FROM users LIMIT 10"
```

The script will:
1. Find database by matching description in config
2. Start SSH tunnel (if configured)
3. Execute query
4. **Automatically close SSH tunnel** (important for cleanup)

### With Custom Config Path

```bash
python3 /usr/lib/node_modules/clawdbot/skills/db-query/scripts/db_query.py \
  --config /path/to/custom-config.json \
  --database "test" \
  --query "SHOW TABLES"
```

## Requirements

- MySQL client: `apt install mysql-client` or equivalent
- SSH client: usually pre-installed on Linux/Mac
- Python 3.6+

## Notes

- SSH tunnels are automatically closed after query execution
- Use `--list` to see all configured databases and their descriptions
- Database search is case-insensitive partial match on `name` field
- Local ports for SSH tunnels should be unique per database

「开发编程」分类下的热门技能

数据月份:2026-10 · 下载/星标数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。