MySQL MCP 服务器实现了模型上下文协议(MCP),让 AI 应用程序与 MySQL 数据库能进行安全交互。该服务器组件借助受控接口,促进 AI 应用程序(主机/客户端)和 MySQL 数据库之间的通信,让数据库的探索与分析更安全、更具结构化。
MySQL MCP 服务器并非独立运行的服务器,而是作为 AI 应用程序与 MySQL 数据库之间通信协议的实现组件。
pip install mysql-mcp-server
自动通过 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_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"
}
}
}
}
配置 launch.json 文件以支持调试:
{
"version": "0.2.0",
"configurations": [
{
"name": "启动 MySQL MCP 服务器",
"type": "python",
"request": "launch",
"program": "path/to/mysql_mcp_server/__main__.py",
"args": []
}
]
}
要为项目做出贡献,请按照以下步骤操作:
git clone https://github.com/yourusername/mysql-mcp-server.gitpip install -r requirements.txtpytest tests/项目使用 MIT License。
git clone https://github.com/yourusername/mysql-mcp-server.gitgit checkout -b feature/amazing-featuregit commit -m '实现惊人的新特性'git push origin feature/amazing-feature通过遵循这些步骤,您可以为项目的发展做出宝贵贡献。