Back to MCP directory
publicPublicdnsLocal runtime

mcp-mysql-server

一个提供MySQL数据库操作的MCP协议服务器,允许AI模型通过标准化接口与MySQL数据库交互。

article

README

🚀 @f4ww4z/mcp-mysql-server 项目文档

一个提供 MySQL 数据库操作的模型上下文协议(Model Context Protocol)服务器。该服务器能让 AI 模型借助标准化接口与 MySQL 数据库进行交互。

smithery badge

🚀 快速开始

本项目是一个提供 MySQL 数据库操作的模型上下文协议服务器,可助力 AI 模型与 MySQL 数据库实现交互。下面将详细介绍其安装、配置及使用方法。

📦 安装指南

使用 Smithery 安装

通过 Smithery 可自动安装 MySQL Server for 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"
      }
    }
  }
}

可用工具

💻 使用示例

基础用法

本服务器提供了多个工具,以下是各工具的使用示例:

1. connect_db

使用提供的凭证建立 MySQL 数据库连接。

use_mcp_tool({
  server_name: "mysql",
  tool_name: "connect_db",
  arguments: {
    host: "localhost",
    user: "your_user",
    password: "your_password",
    database: "your_database"
  }
});
2. query

执行 SELECT 查询,支持可选的预编译语句参数。

use_mcp_tool({
  server_name: "mysql",
  tool_name: "query",
  arguments: {
    sql: "SELECT * FROM users WHERE id = ?",
    params: [1]
  }
});
3. execute

执行 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"]
  }
});
4. list_tables

列出数据库中的所有表。

use_mcp_tool({
  server_name: "mysql",
  tool_name: "list_tables",
  arguments: {}
});
5. describe_table

获取特定表的结构信息。

use_mcp_tool({
  server_name: "mysql",
  tool_name: "describe_table",
  // 此处原文档未给出完整代码,保持原样
});
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client