Skip to main content
Glama

MySQL MCP Server

MIT License
580
  • Linux
  • Apple

测试PyPI - 下载

MySQL MCP 服务器

模型上下文协议 (MCP) 实现,可与 MySQL 数据库进行安全交互。此服务器组件促进 AI 应用程序(主机/客户端)与 MySQL 数据库之间的通信,通过受控接口使数据库探索和分析更加安全、结构化。

注意:MySQL MCP Server 并非设计为独立服务器,而是作为 AI 应用程序和 MySQL 数据库之间的通信协议实现。

特征

  • 列出可用的 MySQL 表作为资源
  • 读取表内容
  • 执行 SQL 查询并进行适当的错误处理
  • 通过环境变量保护数据库访问
  • 综合日志记录

安装

手动安装

pip install mysql-mcp-server

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 MySQL MCP 服务器:

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

配置

设置以下环境变量:

MYSQL_HOST=localhost # Database host MYSQL_PORT=3306 # Optional: Database port (defaults to 3306 if not specified) MYSQL_USER=your_username MYSQL_PASSWORD=your_password MYSQL_DATABASE=your_database

用法

使用 Claude Desktop

将其添加到您的claude_desktop_config.json中:

{ "mcpServers": { "mysql": { "command": "uv", "args": [ "--directory", "path/to/mysql_mcp_server", "run", "mysql_mcp_server" ], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } }

使用 Visual Studio Code

将其添加到您的mcp.json中:

{ "servers": { "mysql": { "type": "stdio", "command": "uvx", "args": [ "--from", "mysql-mcp-server", "mysql_mcp_server" ], "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_username", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } }

注意:需要安装 uv 才能正常工作

使用 MCP Inspector 进行调试

虽然 MySQL MCP Server 不打算独立运行或直接从 Python 命令行运行,但您可以使用 MCP Inspector 对其进行调试。

MCP 检查器提供了一种方便的方法来测试和调试您的 MCP 实现:

# Install dependencies pip install -r requirements.txt # Use the MCP Inspector for debugging (do not run directly with Python)

MySQL MCP 服务器旨在与 Claude Desktop 等 AI 应用程序集成,不应直接作为独立的 Python 程序运行。

发展

# Clone the repository git clone https://github.com/yourusername/mysql_mcp_server.git cd mysql_mcp_server # Create virtual environment python -m venv venv source venv/bin/activate # or `venv\Scripts\activate` on Windows # Install development dependencies pip install -r requirements-dev.txt # Run tests pytest

安全注意事项

  • 切勿提交环境变量或凭据
  • 使用具有最低所需权限的数据库用户
  • 考虑实施查询白名单以供生产使用
  • 监控并记录所有数据库操作

安全最佳实践

此 MCP 实现需要数据库访问权限才能运行。出于安全考虑:

  1. 创建具有最小权限的专用 MySQL 用户
  2. 切勿使用根凭据或管理帐户
  3. 将数据库访问限制为仅进行必要的操作
  4. 启用日志记录以用于审计目的
  5. 定期对数据库访问进行安全审查

有关以下方面的详细说明,请参阅MySQL 安全配置指南

  • 创建受限 MySQL 用户
  • 设置适当的权限
  • 监控数据库访问
  • 安全最佳实践

⚠️重要提示:配置数据库访问时始终遵循最小特权原则。

执照

MIT 许可证 - 详情请参阅 LICENSE 文件。

贡献

  1. 分叉存储库
  2. 创建你的功能分支( git checkout -b feature/amazing-feature
  3. 提交您的更改( git commit -m 'Add some amazing feature'
  4. 推送到分支( git push origin feature/amazing-feature
  5. 打开拉取请求

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

允许AI助手通过受控界面列出表格、读取数据和执行SQL查询,从而使数据库探索和分析更安全、更有条理。

  1. 特征
    1. 安装
      1. 手动安装
      2. 通过 Smithery 安装
    2. 配置
      1. 用法
        1. 使用 Claude Desktop
        2. 使用 Visual Studio Code
        3. 使用 MCP Inspector 进行调试
      2. 发展
        1. 安全注意事项
          1. 安全最佳实践
            1. 执照
              1. 贡献

                Related MCP Servers

                • A
                  security
                  F
                  license
                  A
                  quality
                  Enables AI models to perform MySQL database operations through a standardized interface, supporting secure connections, query execution, and comprehensive schema management.
                  Last updated -
                  7
                  35
                  22
                  JavaScript
                • -
                  security
                  F
                  license
                  -
                  quality
                  Enables AI assistants to interact with Metabase databases and dashboards, allowing users to list and execute queries, access data visualizations, and interact with database resources through natural language.
                  Last updated -
                  25
                  JavaScript
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  A tool that provides simple API to execute SQL queries and manage MySQL databases, designed to integrate with Cursor IDE for AI assistants to directly perform database operations.
                  Last updated -
                  Python
                  • Linux
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
                  Last updated -
                  Python
                  • Linux
                  • Apple

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/designcomputer/mysql_mcp_server'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server