标题: 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 特点
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 开发