这是一个提供MySQL数据库操作的模型上下文协议(Model Context Protocol)服务器,允许AI模型通过标准化接口与MySQL数据库进行交互。
该服务器允许AI模型通过标准化接口与MySQL数据库交互,为数据库操作提供了便捷的途径。
要自动通过Smithery安装MySQL服务器用于Claude Desktop,可使用以下命令:
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"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}
使用提供的凭据建立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