npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@listenfeng/mw-mysql-cli

v1.1.0

Published

Multi-instance MySQL CLI - read-only queries across multiple MySQL databases

Downloads

192

Readme

@listenfeng/mw-mysql-cli

多实例 MySQL 只读查询 CLI 工具,一个命令管理多个数据库。

安装

npm install -g @listenfeng/mw-mysql-cli

快速开始

1. 创建配置文件

mkdir -p ~/.mw-mysql-cli

创建 ~/.mw-mysql-cli/db-config.json

{
  "defaults": {
    "user": "readonly",
    "password": "${MYSQL_READONLY_PWD}",
    "port": 3306,
    "queryTimeout": 30000,
    "maxRows": 1000,
    "poolSize": 5
  },
  "instances": {
    "prod": { "host": "10.1.1.2", "desc": "生产库" },
    "test": { "host": "10.2.2.2", "desc": "测试库" }
  }
}

2. 设置密码环境变量

# Windows
setx MYSQL_READONLY_PWD "your_password"

# Linux/Mac
echo 'export MYSQL_READONLY_PWD="your_password"' >> ~/.bashrc && source ~/.bashrc

3. 使用

mysql-cli list_instances
mysql-cli instance_status prod
mysql-cli list_tables prod my_database
mysql-cli describe_table prod my_database users
mysql-cli mysql_query prod my_database "SELECT * FROM users LIMIT 10"
mysql-cli show_variables prod "%timeout%"

命令列表

| 命令 | 参数 | 说明 | |------|------|------| | list_instances | 无 | 列出所有已配置实例 | | instance_status | <instance> | 检查实例连接状态 | | list_databases | <instance> | 列出实例下所有数据库 | | list_tables | <instance> <database> | 列出库中所有表 | | describe_table | <instance> <database> <table> | 查看表结构 | | show_create_table | <instance> <database> <table> | 查看建表语句 | | show_indexes | <instance> <database> <table> | 查看表索引 | | mysql_query | <instance> <database> <sql> | 执行只读 SQL 查询 | | explain_query | <instance> <database> <sql> | 分析 SQL 执行计划 | | show_variables | <instance> [filter] | 查看系统变量 | | show_status | <instance> [filter] | 查看服务器状态 | | show_processlist | <instance> | 查看当前连接 |

配置说明

  • defaults — 公共默认值,每个实例自动继承
  • instances — 实例列表,每个实例可覆盖 defaults 中的任意字段
  • ${MYSQL_READONLY_PWD} — 环境变量占位符,运行时自动替换

实例级覆盖示例(独立账号):

"pay_db": {
  "host": "10.5.5.2",
  "port": 3307,
  "user": "pay_readonly",
  "password": "${MYSQL_PAY_PWD}",
  "desc": "支付库"
}

配置文件查找优先级

  1. 环境变量 MYSQL_CLI_CONFIG 指定路径
  2. ~/.mw-mysql-cli/db-config.json(推荐)
  3. 当前工作目录 db-config.json

安全说明

  • 仅允许 SELECT / SHOW / DESCRIBE / EXPLAIN
  • 自动拦截 INSERT / UPDATE / DELETE / DROP / ALTER
  • 结果默认最多 1000 行
  • 密码通过环境变量注入,不写入配置

环境要求

  • Node.js >= 20