这是一个提供MySQL数据库操作的Model Context Protocol服务器。该服务器使AI模型能够通过标准化接口与MySQL数据库进行交互。
<a href="https://glama.ai/mcp/servers/qma33al6ie"><img width="380" height="200" src="https://gips2.baidu.com/it/u=929586495,1029864305&fm=3081&app=3081&f=PNG?w=760&h=400" alt="mcp-mysql-server MCP服务器" /></a>
要通过Smithery自动安装Claude Desktop的MySQL服务器:
npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude
npx @f4ww4z/mcp-mysql-server
服务器需要在您的MCP设置配置文件中设置以下环境变量:
推荐使用
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:port/database"],
}
}
}
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@f4ww4z/mcp-mysql-server"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}
在 ~/.codex/config.toml
[mcp_servers.mcp-mysql-server]
command = "npx"
args = [
"-y",
"@f4ww4z/mcp-mysql-server",
"mysql://user:password@127.0.0.1:3306/database"
]
在 %USERPROFILE%\.codex\config.toml
[mcp_servers.mcp-mysql-server]
command = "npx"
args = [
"-y",
"@f4ww4z/mcp-mysql-server",
"mysql://user:password@127.0.0.1:3306/database"
]
评估包加载一个mcp客户端,然后运行index.ts文件,因此在测试之间不需要重新构建。您可以通过在npx命令前添加环境变量来加载它们。完整的文档可以在这里找到:这里。
OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts src/index.ts
使用提供的凭据建立与MySQL数据库的连接。
use_mcp_tool({
server_name: "mysql",
tool_name: "connect_db",
arguments: {
host: "localhost",
user: "your_user",
password: "your_password",
database: "your_database"
}
});
执行带有可选预处理语句参数的SELECT查询。
use_mcp_tool({
server_name: "mysql",
tool_name: "query",
arguments: {
sql: "SELECT * FROM users WHERE id = ?",
params: [1]
}
});
执行带有可选预处理语句参数的INSERT、UPDATE或DELETE查询。
use_mcp_tool({
server_name: "mysql",
tool_name: "execute",
arguments: {
sql: "INSERT INTO users (name, email) VALUES (?, ?)",
params: ["John Doe", "john@example.com"]
}
});
列出连接数据库中的所有表。
use_mcp_tool({
server_name: "mysql",
tool_name: "list_tables",
arguments: {}
});
获取特定表的结构。
use_mcp_tool({
server_name: "mysql",
tool_name: "describe_table",
arguments: {
table: "users"
}
});
服务器提供了常见问题的详细错误消息:
欢迎贡献!请随意提交Pull Request到 https://github.com/f4ww4z/mcp-mysql-server
MIT