Mysql_mcp_server

Mysql_mcp_server

🚀 MySQL MCP 服务器

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

🚀 快速开始

MySQL MCP 服务器并非独立运行的服务器,而是作为 AI 应用程序与 MySQL 数据库之间通信协议的实现组件。

✨ 主要特性

  • 🔖 列出可用的 MySQL 表作为资源
  • 📖 读取表内容
  • 🛠️ 执行 SQL 查询并带有错误处理
  • 🔐 通过环境变量实现数据库的安全访问
  • 📜 全面的日志记录

📦 安装指南

手动安装

pip install mysql-mcp-server

使用 Smithery 安装

自动通过 Smithery 安装 MySQL MCP Server 以供 Claude 桌面使用:

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

🛠️ 配置

设置以下环境变量:

MYSQL_HOST=localhost     # 数据库主机
MYSQL_PORT=3306         # 可选:数据库端口(未指定时默认为 3306)
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database

💻 使用示例

基础用法

在 Claude 桌面中使用

将以下内容添加到 claude_desktop_config.json

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

在 Visual Studio Code 中使用

配置 launch.json 文件以支持调试:

{
"version": "0.2.0",
"configurations": [
{
"name": "启动 MySQL MCP 服务器",
"type": "python",
"request": "launch",
"program": "path/to/mysql_mcp_server/__main__.py",
"args": []
}
]
}

👨‍💻 开发

要为项目做出贡献,请按照以下步骤操作:

  1. 克隆仓库:git clone https://github.com/yourusername/mysql-mcp-server.git
  2. 安装依赖项:pip install -r requirements.txt
  3. 启动测试环境:pytest tests/

⚠️ 安全注意事项

  • 切勿提交环境变量或凭证到版本控制系统。
  • 使用 HTTPS 保护数据库连接。
  • 定期更新数据库凭据。

💡 最佳实践

  • 避免在生产环境中暴露数据库端口。
  • 使用防火墙限制数据库访问。
  • 配置审计日志以监控敏感操作。

📄 许可证

项目使用 MIT License。

🤝 贡献指南

  1. 克隆仓库:git clone https://github.com/yourusername/mysql-mcp-server.git
  2. 创建功能分支:git checkout -b feature/amazing-feature
  3. 提交更改:git commit -m '实现惊人的新特性'
  4. 推送到分支:git push origin feature/amazing-feature
  5. 提交拉取请求

通过遵循这些步骤,您可以为项目的发展做出宝贵贡献。

  • 0 关注
  • 0 收藏,21 浏览
  • system 提出于 2025-09-24 09:12

相似服务问题

相关AI产品