马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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 特点
- List available MySQL tables as resources
列出可用的 MySQL 表资源
- Read table contents 读取表内容
- Execute SQL queries with proper error handling
执行 SQL 查询并正确处理错误
- Secure database access through environment variables
通过环境变量安全访问数据库
- Comprehensive logging 完善的日记记录
Installation 安装
Manual Installation 手动安装
- 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:
- npx -y @smithery/cli install mysql-mcp-server --client claude
复制代码 Configuration 配置
Set the following environment variables:
设置以下环境变量:
- 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
复制代码 Usage 用法
With Claude Desktop 使用 Claude 桌面版
Add this to your claude_desktop_config.json:
将此添加到您的 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"
- }
- }
- }
- }
复制代码 With Visual Studio Code 使用 Visual Studio Code
Add this to your mcp.json:
将此添加到您的 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"
- }
- }
- }
复制代码 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 实现:
- # Install dependencies
- pip install -r requirements.txt
- # 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 开发
- # Clone the repository
- git clone https://kkgithub.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
复制代码 Security Considerations 安全思量
- Never commit environment variables or credentials
永世不要提交环境变量或凭证
- Use a database user with minimal required permissions
使用具有最小须要权限的数据库用户
- Consider implementing query whitelisting for production use
思量在生产环境中实验查询白名单
- Monitor and log all database operations
监控并记录所有数据库操纵
Security Best Practices 安全最佳实践
This MCP implementation requires database access to function. For security:
此 MCP 实现需要数据库访问才华运行。为了安全:
- Create a dedicated MySQL user with minimal permissions
创建具有最小权限的专用 MySQL 用户
- Never use root credentials or administrative accounts
永世不要使用 root 凭证或管理员账户
- Restrict database access to only necessary operations
仅允许须要的操纵访问数据库
- Enable logging for audit purposes
启用日记记录以供审计
- Regular security reviews of database access
定期举行数据库访问的安全审查
See MySQL Security Configuration Guide for detailed instructions on:
查看 MySQL 安全配置指南以获取有关以下内容的具体说明:
- Creating a restricted MySQL user
创建受限的 MySQL 用户
- Setting appropriate permissions
设置恰当的权限
- Monitoring database access
监控数据库访问
- Security best practices 安全最佳实践
⚠️ IMPORTANT: Always follow the principle of least privilege when configuring database access.
⚠️ 重要:配置数据库访问时始终遵照最小权限原则。
links:
https://kkgithub.com/designcomputer/mysql_mcp_server
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |