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

@fhuang/mcp-mysql-server

v1.2.0

Published

The Model Context Protocol (MCP) server establishes a standardized JSON-RPC 2.0 interface for MySQL operations, enabling CRUD execution, transaction management, and ddl

Downloads

752

Readme

@fhuang/mcp-mysql-server 中文说明

一个基于 Model Context Protocol (MCP) 的 MySQL 数据库服务端,支持 AI 模型通过标准接口安全地操作 MySQL 数据库。


安装方法

1. 使用 Smithery 自动安装

npx -y @smithery/cli install @fhuang/mcp-mysql-server --client claude

2. 手动安装

npx @fhuang/mcp-mysql-server

配置方法

在 MCP 配置文件中设置数据库连接参数,支持两种方式:

方式一:URL 方式

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@fhuang/mcp-mysql-server", "mysql://user:password@localhost:port/database"]
    }
  }
}

方式二:环境变量方式

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@fhuang/mcp-mysql-server"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

用法示例

  1. 连接数据库
  2. 执行查询、插入、更新、删除等操作
  3. 列出所有表和表结构

示例代码:

// 连接数据库
use_mcp_tool({
  server_name: "mysql",
  tool_name: "connect_db",
  arguments: {
    host: "localhost",
    user: "your_user",
    password: "your_password",
    database: "your_database"
  }
});

// 查询
use_mcp_tool({
  server_name: "mysql",
  tool_name: "query",
  arguments: {
    sql: "SELECT * FROM users WHERE id = ?",
    params: [1]
  }
});

主要功能

  • 自动安全管理数据库连接
  • 支持参数化查询,防止 SQL 注入
  • 错误详细提示
  • TypeScript 支持
  • 自动关闭连接
  • 支持SQL性能分析(EXPLAIN)

可用工具

7. explain

分析SQL查询性能,返回执行计划详情,包括访问类型、扫描行数和可能的优化建议。

use_mcp_tool({
  server_name: "mysql",
  tool_name: "explain",
  arguments: {
    sql: "SELECT * FROM users WHERE id = ?"
  }
});

安全性

  • 所有查询均使用参数化语句
  • 密码等敏感信息通过环境变量管理
  • 查询前自动校验
  • 连接用完自动关闭

错误处理

  • 连接失败、参数缺失、SQL 错误等均有详细报错信息

贡献

欢迎提交 Pull Request!
GitHub 地址:https://github.com/huangfeng19820712/mcp-mysql-server


许可证

MIT