qidao123.com技术社区-IT企服评测·应用市场

标题: mysql-mcp-server安装及配置指南 [打印本页]

作者: 反转基因福娃    时间: 2025-4-23 11:42
标题: mysql-mcp-server安装及配置指南
MySQL MCP Server MySQL MCP 服务器

A Model Context Protocol (MCP) implementation that enables secure interaction with MySQL databases. This server component facilitates communication between AI applications (hosts/clients) and MySQL databases, making database exploration and analysis safer and more structured through a controlled interface.
模子上下文协议(MCP)实现,可安全地与 MySQL 数据库举行交互。该服务器组件促进了 AI 应用(主机/客户端)与 MySQL 数据库之间的通信,通过受控接口使数据库探索和分析更加安全且结构化。
   Note: MySQL MCP Server is not designed to be used as a standalone server, but rather as a communication protocol implementation between AI applications and MySQL databases.
注意:MySQL MCP 服务器不是筹划为独立服务器使用,而是作为 AI 应用与 MySQL 数据库之间的通信协议实现。
  Features 特点


Installation 安装

Manual Installation 手动安装

  1. pip install mysql-mcp-server
复制代码
Installing via Smithery 通过 Smithery 安装

To install MySQL MCP Server for Claude Desktop automatically via Smithery:
通过 Smithery 自动安装 MySQL MCP Server for Claude Desktop:
  1. npx -y @smithery/cli install mysql-mcp-server --client claude
复制代码
Configuration 配置

Set the following environment variables:
设置以下环境变量:
  1. MYSQL_HOST=localhost     # Database host
  2. MYSQL_PORT=3306         # Optional: Database port (defaults to 3306 if not specified)
  3. MYSQL_USER=your_username
  4. MYSQL_PASSWORD=your_password
  5. MYSQL_DATABASE=your_database
复制代码
Usage 用法

With Claude Desktop 使用 Claude 桌面版

Add this to your claude_desktop_config.json:
将此添加到您的 claude_desktop_config.json :
  1. {
  2.   "mcpServers": {
  3.     "mysql": {
  4.       "command": "uv",
  5.       "args": [
  6.         "--directory",
  7.         "path/to/mysql_mcp_server",
  8.         "run",
  9.         "mysql_mcp_server"
  10.       ],
  11.       "env": {
  12.         "MYSQL_HOST": "localhost",
  13.         "MYSQL_PORT": "3306",
  14.         "MYSQL_USER": "your_username",
  15.         "MYSQL_PASSWORD": "your_password",
  16.         "MYSQL_DATABASE": "your_database"
  17.       }
  18.     }
  19.   }
  20. }
复制代码
With Visual Studio Code 使用 Visual Studio Code

Add this to your mcp.json:
将此添加到您的 mcp.json :
  1. {
  2.   "servers": {
  3.       "mysql": {
  4.             "type": "stdio",
  5.             "command": "uvx",
  6.             "args": [
  7.                 "--from",
  8.                 "mysql-mcp-server",
  9.                 "mysql_mcp_server"
  10.             ],
  11.       "env": {
  12.         "MYSQL_HOST": "localhost",
  13.         "MYSQL_PORT": "3306",
  14.         "MYSQL_USER": "your_username",
  15.         "MYSQL_PASSWORD": "your_password",
  16.         "MYSQL_DATABASE": "your_database"
  17.       }
  18.   }
  19. }
复制代码
Note: Will need to install uv for this to work
注意:要使此功能正常工作,需要安装 uv
Debugging with MCP Inspector 使用 MCP Inspector 举行调试

While MySQL MCP Server isn’t intended to be run standalone or directly from the command line with Python, you can use the MCP Inspector to debug it.
虽然 MySQL MCP Server 不打算独立运行或直接通过 Python 下令行运行,但您可以使用 MCP Inspector 来调试它。
The MCP Inspector provides a convenient way to test and debug your MCP implementation:
MCP Inspector 提供了一个方便的方式来测试和调试您的 MCP 实现:
  1. # Install dependencies
  2. pip install -r requirements.txt
  3. # Use the MCP Inspector for debugging (do not run directly with Python)
复制代码
The MySQL MCP Server is designed to be integrated with AI applications like Claude Desktop and should not be run directly as a standalone Python program.
MySQL MCP 服务器旨在与 Claude 桌面等 AI 应用程序集成,不应直接作为独立的 Python 程序运行。
Development 开发

  1. # Clone the repository
  2. git clone https://kkgithub.com/yourusername/mysql_mcp_server.git
  3. cd mysql_mcp_server
  4. # Create virtual environment
  5. python -m venv venv
  6. source venv/bin/activate  # or `venv\Scripts\activate` on Windows
  7. # Install development dependencies
  8. pip install -r requirements-dev.txt
  9. # Run tests
  10. pytest
复制代码
Security Considerations 安全思量


Security Best Practices 安全最佳实践

This MCP implementation requires database access to function. For security:
此 MCP 实现需要数据库访问才华运行。为了安全:
See MySQL Security Configuration Guide for detailed instructions on:
查看 MySQL 安全配置指南以获取有关以下内容的具体说明:

⚠️ IMPORTANT: Always follow the principle of least privilege when configuring database access.
⚠️ 重要:配置数据库访问时始终遵照最小权限原则。

links:

https://kkgithub.com/designcomputer/mysql_mcp_server

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 qidao123.com技术社区-IT企服评测·应用市场 (https://dis.qidao123.com/) Powered by Discuz! X3.4