能力标签
MCP MySQL 服务器
🔌
MCP工具

MCP MySQL 服务器

基于 Go · 让 AI 助手直接操作你的系统与工具
英文名:mysql-mcp-server
⭐ 35 Stars 🍴 9 Forks 💻 Go 📄 NOASSERTION 🏷 AI 7.5分
7.5AI 综合评分
mcpgomysql
⚙️ 配置说明
✦ AI Skill Hub 推荐

经 AI Skill Hub 精选评估,MCP MySQL 服务器 获评「推荐使用」。这款MCP工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。

📚 深度解析

MCP MySQL 服务器 是一款基于 MCP(Model Context Protocol)标准协议的 AI 工具扩展。MCP 协议由 Anthropic 开发并开源,旨在建立 AI 模型与外部工具之间的标准化通信接口,目前已被 Claude Desktop、Claude Code、Cursor 等主流 AI 工具采纳。

通过安装 MCP MySQL 服务器,你的 AI 助手将获得额外的工具调用能力,可以用自然语言直接操控该工具的功能,无需学习复杂的命令行语法。MCP 工具的核心价值在于"一次配置,永久增强"——配置完成后,每次与 AI 对话时都可以无缝调用这些工具。

在技术实现上,MCP 工具通过标准的 JSON-RPC 协议与 AI 客户端通信,工具的功能以"工具列表"的形式暴露给 AI 模型,AI 可以按需调用。MCP MySQL 服务器 提供了结构化的工具调用接口,使 AI 模型能够精确地理解和使用每个功能点,显著降低 AI 在工具使用上的错误率。

与传统的 API 集成相比,MCP 工具的优势在于无需编写代码——用户只需在配置文件中添加几行 JSON,即可让 AI 获得全新能力。AI Skill Hub 将 MCP MySQL 服务器 评为 AI 评分 7.5 分,属于同类工具中的优质选择。

📋 工具概览

MCP MySQL 服务器 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。

GitHub Stars
⭐ 35
开发语言
Go
支持平台
Windows / macOS / Linux(跨平台)
维护状态
轻量级项目,按需更新
开源协议
NOASSERTION
AI 综合评分
7.5 分
工具类型
MCP工具
Forks
9

📖 中文文档

以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

MCP MySQL 服务器 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。

📌 核心特色
  • 通过标准 MCP 协议与 Claude、Cursor 等主流 AI 客户端深度集成
  • 提供结构化工具调用接口,显著降低 AI 集成复杂度
  • 支持 Claude Desktop 和 Claude Code 无缝接入,开箱即用
  • 可与其他 MCP 工具组合叠加,构建完整 AI 工作站
  • 轻量无侵入设计,不影响现有系统架构
🎯 主要使用场景
  • 在 Claude Desktop 对话中直接调用本地工具,实现 AI 与系统的深度联动
  • 通过自然语言驱动复杂的多步骤自动化任务,代替繁琐手动操作
  • 将多个 MCP 工具组合使用,构建个人专属 AI 工作站
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/askdba/mysql-mcp-server

# 方式二:手动配置 claude_desktop_config.json
{
  "mcpServers": {
    "mcp-mysql----": {
      "command": "npx",
      "args": ["-y", "mysql-mcp-server"]
    }
  }
}

# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
📋 安装步骤说明
  1. 确认已安装 Node.js(v18 或以上版本)
  2. 打开 Claude Desktop 或 Claude Code 的 MCP 配置文件
  3. 按「交给 Agent 安装 → Claude Desktop」标签中的 JSON 配置填入 mcpServers 字段
  4. 保存配置文件并重启 Claude 客户端
  5. 重启后,在对话中即可使用本工具
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 安装后在 Claude 对话中直接使用
# 示例:
用户: 请帮我用 MCP MySQL 服务器 执行以下任务...
Claude: [自动调用 MCP MySQL 服务器 MCP 工具处理请求]

# 查看可用工具列表
# 在 Claude 中输入:"列出所有可用的 MCP 工具"
以下配置示例基于典型使用场景生成,具体参数请参照官方文档调整。
配置示例
// claude_desktop_config.json 配置示例
{
  "mcpServers": {
    "mcp_mysql____": {
      "command": "npx",
      "args": ["-y", "mysql-mcp-server"],
      "env": {
        // "API_KEY": "your-api-key-here"
      }
    }
  }
}

// 保存后重启 Claude Desktop 生效
📑 README 深度解析 真实文档 完整度 82/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

MySQL MCP Server

MySQL MCP Server Banner [![Version](https://img.shields.io/badge/version-1.7.1-blue.svg)](https://github.com/askdba/mysql-mcp-server/releases) [![Go](https://img.shields.io/badge/go-1.24+-00ADD8.svg)](https://golang.org/) [![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)

A fast, read-only MySQL Server for the Model Context Protocol (MCP) written in Go.

This project exposes safe MySQL introspection tools to Claude Desktop via MCP. Claude can explore databases, describe schemas, and execute controlled read-only SQL queries — ideal for secure development assistance, debugging, analytics, and schema documentation.

Features

  • Fully read-only (blocks all non-SELECT/SHOW/DESCRIBE/EXPLAIN)
  • Multi-DSN Support: Connect to multiple MySQL or MariaDB instances, switch via tool
  • MariaDB Support: Native compatibility with MariaDB 10.x and 11.x
  • Vector Search (MySQL 9.0+): Similarity search on vector columns
  • MCP tools:
  • list_databases, list_tables, describe_table
  • run_query (safe and row-limited)
  • ping, server_info
  • list_connections, use_connection (multi-DSN)
  • vector_search, vector_info (MySQL 9.0+)
  • Supports MySQL 8.0, 8.4, 9.0+ and MariaDB 10.x, 11.x
  • Query timeouts, structured logging, audit logs; optional live token metrics and /status dashboard in HTTP mode
  • Performance: configurable pool/query timeouts, server-side row caps, explain_query plan warnings
  • Single Go binary
  • Unit and integration tests (Testcontainers)
  • Native integration with Claude Desktop MCP

Features

features: extended_tools: true vector_tools: false

Prerequisites

  • Go 1.24+
  • Docker and Docker Compose (for integration tests)
  • MySQL client (optional, for manual database access)

Installation

Docker

docker pull ghcr.io/askdba/mysql-mcp-server:latest
Note: Docker image tags use the raw version number without a leading "v" (e.g., 1.5.0, not v1.5.0).

Build from Source

git clone https://github.com/askdba/mysql-mcp-server.git
cd mysql-mcp-server
make build

Binary output: bin/mysql-mcp-server

Option B: Build from Source

git clone https://github.com/askdba/mysql-mcp-server.git
cd mysql-mcp-server
make build

When running from a cloned repo you can also use the interactive setup script:

./scripts/quickstart.sh

This will test your MySQL connection, optionally create a read-only MCP user, and generate your Claude Desktop configuration.

Option 1: CLI (quick setup)

claude mcp add --transport stdio \
  --env MYSQL_DSN="user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true" \
  --env MYSQL_MCP_EXTENDED=1 \
  mysql -- mysql-mcp-server

MySQL 8.0 (host port 13306 in docker-compose.test.yml — avoids local MySQL on 3306)

export MYSQL_TEST_DSN="mcpuser:mcppass00@tcp(127.0.0.1:13306)/testdb?parseTime=true"

Docker

Claude Desktop with Docker

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "mysql": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "MYSQL_DSN=user:password@tcp(host.docker.internal:3306)/mydb",
        "ghcr.io/askdba/mysql-mcp-server:latest"
      ]
    }
  }
}

With extended tools:

{
  "mcpServers": {
    "mysql": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "MYSQL_DSN=user:password@tcp(host.docker.internal:3306)/mydb",
        "-e", "MYSQL_MCP_EXTENDED=1",
        "ghcr.io/askdba/mysql-mcp-server:latest"
      ]
    }
  }
}

Docker Compose

services:
  mysql:
    image: mysql:8.4
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: testdb
    ports:
      - "3306:3306"

  mcp:
    image: ghcr.io/askdba/mysql-mcp-server:latest
    depends_on:
      - mysql
    environment:
      MYSQL_DSN: "root:rootpass@tcp(mysql:3306)/testdb?parseTime=true"
      MYSQL_MCP_EXTENDED: "1"

Run:

docker compose up

Build Locally

docker build -t mysql-mcp-server .

Docker with REST API

docker run -p 9306:9306 \
  -e MYSQL_DSN="user:password@tcp(host.docker.internal:3306)/mydb" \
  -e MYSQL_MCP_HTTP=1 \
  -e MYSQL_MCP_EXTENDED=1 \
  ghcr.io/askdba/mysql-mcp-server:latest

Quickstart

Token Usage Estimation (Optional)

Enable estimated token counting for tool inputs/outputs to monitor LLM context usage:

export MYSQL_MCP_TOKEN_TRACKING=1
export MYSQL_MCP_TOKEN_MODEL=cl100k_base  # default, used by GPT-4/Claude

Or via YAML config file:

logging:
  token_tracking: true
  token_model: "cl100k_base"

When enabled: - JSON logs include a tokens object with estimated input/output/total tokens - Audit log entries for run_query include input_tokens and output_tokens - All other tools also emit token estimates when token_tracking is enabled

Example JSON log output:

{
  "level": "INFO",
  "msg": "query executed",
  "tool": "run_query",
  "duration_ms": 45,
  "row_count": 10,
  "tokens": {
    "input_estimated": 25,
    "output_estimated": 150,
    "total_estimated": 175,
    "model": "cl100k_base"
  }
}

Notes: - Token counts are estimates using tiktoken encoding, not actual LLM billing - For payloads exceeding 1MB, a heuristic (~4 bytes per token) is used to prevent memory spikes - The feature is disabled by default to avoid overhead when not needed

Example Usage

List databases:

curl http://localhost:9306/api/databases

Run a query:

curl -X POST http://localhost:9306/api/query \
  -H "Content-Type: application/json" \
  -d '{"sql": "SELECT * FROM users LIMIT 5", "database": "myapp"}'

Get server info:

curl http://localhost:9306/api/server-info

List / switch connections (no HTTP “add” endpoint):

curl http://localhost:9306/api/connections
curl -X POST http://localhost:9306/api/connections/use \
  -H "Content-Type: application/json" \
  -d '{"name": "staging"}'
Registering a new DSN at runtime is MCP-only via the add_connection tool when MYSQL_MCP_ENABLE_ADD_CONNECTION=1 (see add_connection).

Examples

The examples/ folder contains:

  • claude_desktop_config.json - Example Claude Desktop configuration
  • test-dataset.sql - Demo database with tables, views, and sample data

Load the test dataset:

mysql -u root -p < examples/test-dataset.sql

This creates a mcp_demo database with: - 5 categories, 13 products, 8 customers - 9 orders with 16 order items - Views: order_summary, product_inventory - Stored procedure: GetCustomerOrders - Stored function: GetProductStock

Option A: Homebrew (macOS/Linux)

brew install askdba/tap/mysql-mcp-server
mysql-mcp-server --version

Then follow the client-specific setup in the Claude Desktop, Claude Code, or Cursor IDE sections below.

Tip: brew info askdba/tap/mysql-mcp-server shows a config reminder after install.

Configuration

Environment variables:

VariableRequiredDefaultDescription
MYSQL_DSNYesMySQL DSN
MYSQL_MAX_ROWSNo200Max rows returned per query
MYSQL_QUERY_TIMEOUT_SECONDSNo30Query timeout (seconds); wins over MYSQL_QUERY_TIMEOUT when both are set
MYSQL_QUERY_TIMEOUTNoQuery timeout in **milliseconds** (e.g. 30000); used only if MYSQL_QUERY_TIMEOUT_SECONDS is unset
MYSQL_POOL_SIZENoAlias for MYSQL_MAX_OPEN_CONNS (pool size); MYSQL_MAX_OPEN_CONNS overrides when both are set
MYSQL_MCP_EXTENDEDNo0Enable extended tools (set to 1)
MYSQL_MCP_ENABLE_ADD_CONNECTIONNo0Set 1 to expose the MCP tool **add_connection** (runtime DSN registration; see [add_connection](#add_connection)). Requires **MYSQL_MCP_EXTENDED=1**. Not available over the HTTP REST API.
MYSQL_MCP_JSON_LOGSNo0Enable JSON structured logging (set to 1)
MYSQL_MCP_TOKEN_TRACKINGNo0Enable estimated token usage tracking (set to 1)
MYSQL_MCP_TOKEN_MODELNocl100k_baseTokenizer encoding to use for estimation
MYSQL_MCP_TOKEN_CARDNo**on** when MYSQL_MCP_HTTP is set**/status** live token dashboard + listing in **GET /api**; omit to use default **on**; set to **0** to disable
MYSQL_MCP_AUDIT_LOGNoPath to audit log file
MYSQL_MCP_ALLOWED_DATABASESNoComma-separated schema allowlist (empty = all allowed). With an allowlist, **run_query** rejects **SHOW DATABASES** / **SHOW DATABASES LIKE**—use **list_databases**.
MYSQL_MCP_STRICT_READ_ONLYNo0Set 1 to enable transaction_read_only=ON on new connections
MYSQL_MCP_ALLOW_SYSTEM_SCHEMASNo0Set 1 to allow **read-only** access to information_schema, performance_schema, and sys (for diagnostics: index cardinality, index usage, redundant/unused indexes). mysql stays blocked regardless.
MYSQL_MCP_PROCESS_ADMINNo0Set 1 to enable **process_list** / **kill_query** (extended); **kill_query** issues **KILL QUERY** (cancels the running statement only, not the connection)
MYSQL_MCP_READ_AUDIT_TOOLNo0Set 1 to enable read_audit_log when audit path is set
MYSQL_MCP_SLOW_QUERY_TOOLNo0Set 1 to enable slow_query_log tool (extended)
MYSQL_MCP_VECTORNo0Enable vector tools for MySQL 9.0+ (set to 1)
MYSQL_MCP_HTTPNo0Enable REST API mode (set to 1); **mutually exclusive** with stdio MCP
MYSQL_MCP_METRICS_HTTPNo0With **stdio MCP only**: expose **/status** + **/api/metrics/tokens** on **MYSQL_HTTP_PORT** (same process as Claude/Cursor)
MYSQL_HTTP_PORTNo9306Port for REST API **or** metrics sidecar
MYSQL_HTTP_RATE_LIMITNo0Enable rate limiting for HTTP mode (set to 1)
MYSQL_HTTP_RATE_LIMIT_RPSNo100Rate limit: requests per second
MYSQL_HTTP_RATE_LIMIT_BURSTNo200Rate limit: burst size
MYSQL_MAX_OPEN_CONNSNo10Max open database connections (overrides MYSQL_POOL_SIZE when both are set)
MYSQL_MAX_IDLE_CONNSNo5Max idle database connections
MYSQL_CONN_MAX_LIFETIME_MINUTESNo30Connection max lifetime in minutes
MYSQL_CONN_MAX_IDLE_TIME_MINUTESNo5Max idle time before connection is closed
MYSQL_PING_TIMEOUT_SECONDSNo5Database ping/health check timeout
MYSQL_MCP_DB_RETRY_MAXNo3Retries for transient errors on **run_query** and **ping** (0 disables retries)
MYSQL_MCP_DB_RETRY_MAX_INTERVAL_MSNo10000Max exponential-backoff interval between retries (milliseconds)
MYSQL_HTTP_REQUEST_TIMEOUT_SECONDSNo60HTTP request timeout in REST API mode
MYSQL_SSLNoEnable SSL/TLS for connections (true, false, skip-verify, preferred)

SSL/TLS Configuration

Enable encrypted connections to MySQL servers:

SSL ValueDescription
trueEnable TLS with certificate verification
falseDisable TLS (default)
skip-verifyEnable TLS without certificate verification (self-signed certs)
preferredMaps to skip-verify (Go MySQL driver limitation)
Note: The Go MySQL driver doesn't support tls=preferred. When you specify preferred, it is automatically mapped to skip-verify to ensure TLS is enabled.

Environment variable:

```bash

Optional: instead of a file, pin the bastion key (from ssh-keygen -lf):

Multi-DSN Configuration

Configure multiple MySQL connections using numbered environment variables:

```bash

Configuration File

As an alternative to environment variables, you can use a YAML or JSON configuration file.

Config file search order: 1. --config /path/to/config.yaml (command line flag) 2. MYSQL_MCP_CONFIG environment variable 3. ./mysql-mcp-server.yaml (current directory) 4. ~/.config/mysql-mcp-server/config.yaml (user config) 5. /etc/mysql-mcp-server/config.yaml (system config)

Example config file (mysql-mcp-server.yaml):

```yaml

Query settings

query: max_rows: 200 timeout_seconds: 30

HTTP/REST API (optional)

http: enabled: false port: 9306


**Command line options:**
bash

Use specific config file

mysql-mcp-server --config /path/to/config.yaml

Validate config file

mysql-mcp-server --validate-config /path/to/config.yaml

Print current configuration as YAML

mysql-mcp-server --print-config

Option 2: Project `.mcp.json`

This repo includes a .mcp.json that Claude Code auto-discovers when you open the project. Set your DSN in the shell before starting Claude Code:

export MYSQL_DSN="user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true"
claude  # start Claude Code — MySQL tools will be available automatically

To use the same config in your own project, copy .mcp.json to your project root and set MYSQL_DSN in your shell.

Verify the integration by asking Claude Code: "List all databases on this MySQL server."

Security options and privileged tools (extended mode)

VariablePurpose
MYSQL_MCP_ALLOWED_DATABASESComma-separated schema allowlist. When set, tools that take a database argument must use an allowed name; list_databases / database_size only expose allowed schemas; run_query requires database and cannot be used to hop schemas via omission. **run_query** rejects **SHOW DATABASES** and **SHOW DATABASES LIKE** (use **list_databases**). Qualified names in SQL, **EXPLAIN** (including **FORMAT=** / **EXTENDED**), and inner DML in **EXPLAIN** are checked against the allowlist. **slow_query_log** (table mode) only returns mysql.slow_log rows whose **db** column matches an allowed schema (case-insensitive); rows with null/empty db are omitted.
MYSQL_MCP_STRICT_READ_ONLYWhen 1, new driver connections run with transaction_read_only=ON (harder to accidentally issue writes if grants allow them).
MYSQL_MCP_ALLOW_SYSTEM_SCHEMASWhen 1, lifts the default block on the read-only diagnostic schemas information_schema, performance_schema, and sys so run_query / explain_query may reference them (e.g. information_schema.STATISTICS for index cardinality, sys.schema_redundant_indexes / sys.schema_unused_indexes, performance_schema.table_io_waits_summary_by_index_usage). The mysql schema remains blocked unconditionally. Off by default; reads still require the connection's MySQL grants. This flag and MYSQL_MCP_ALLOWED_DATABASES are **orthogonal and both enforced**: the flag lifts the hardcoded system-schema guard, while the allowlist (when set) independently rejects any schema not on it. So if you run with an allowlist, you must **also add information_schema / performance_schema / sys to MYSQL_MCP_ALLOWED_DATABASES** for these queries to pass; with no allowlist (the default), the flag alone is sufficient. The flag never unlocks mysql.
MYSQL_MCP_PROCESS_ADMINEnables **process_list** and **kill_query** (issues **KILL QUERY**, not connection kill; plus HTTP /api/processlist, /api/kill). Requires appropriate MySQL privileges (CONNECTION_ADMIN / PROCESS, etc.).
MYSQL_MCP_READ_AUDIT_TOOLEnables **read_audit_log** when **MYSQL_MCP_AUDIT_LOG** is set (tail of the audit JSON file).
MYSQL_MCP_SLOW_QUERY_TOOLEnables **slow_query_log** (reads mysql.slow_log when log_output includes TABLE, otherwise returns file settings).

server_info: Pass detailed: true (MCP) or ?detailed=1 (HTTP) for ping latency, Threads_running, Slow_queries, Questions, and InnoDB buffer pool hit rate when stats are available. If MYSQL_MCP_TOKEN_TRACKING=1, token_metrics is always included (cumulative since process start).

YAML file equivalents live under security: in the config file (allowed_databases, strict_read_only, allow_system_schemas, process_admin, read_audit_tool, slow_query_tool).

Environment Variables

When running tests manually, set the DSN:

```bash

REST API Mode

Enable HTTP REST API mode to use with ChatGPT, Gemini, or any HTTP client:

export MYSQL_DSN="user:password@tcp(localhost:3306)/mydb"
export MYSQL_MCP_HTTP=1
export MYSQL_HTTP_PORT=9306  # Optional, defaults to 9306
mysql-mcp-server

API Endpoints

Discovery (GET /api): The JSON response includes an endpoints map that lists only routes the server has registered for the current configuration—same rules as the mux: core routes always; extended routes only if MYSQL_MCP_EXTENDED=1; /api/processlist and /api/kill only if extended and MYSQL_MCP_PROCESS_ADMIN=1; /api/audit-log only if extended and read-audit is enabled (MYSQL_MCP_READ_AUDIT_TOOL=1 with MYSQL_MCP_AUDIT_LOG); /api/slow-log only if extended and MYSQL_MCP_SLOW_QUERY_TOOL=1; vector routes only if MYSQL_MCP_VECTOR=1; /status appears in the index only when the token card is enabled. modes in the JSON reflects extended, vector, and token_card.

Runtime DSN registration: There is no HTTP route to register a new connection. The MCP tool add_connection (optional; MYSQL_MCP_EXTENDED=1 and MYSQL_MCP_ENABLE_ADD_CONNECTION=1) is the only supported registration path and applies to the MCP (stdio) process only. In REST API mode, the process never registers tools; GET /api/connections lists only connections configured for that HTTP server process (not connections added by MCP elsewhere).

MethodEndpointDescription
GET/healthHealth check
GET/apiAPI index: registered endpoints + **modes** (see Discovery above)
GET/api/databasesList databases
GET/api/tables?database=List tables
GET/api/describe?database=&table=Describe table
POST/api/queryRun SQL query
GET/api/pingPing database
GET/api/server-infoServer info
GET/api/connectionsList connections (masked DSNs) known to **this HTTP server process** (config-loaded; no MCP add_connection in REST mode)
POST/api/connections/useSwitch active connection: JSON body {"name": "<connection_name>"}. Invalid JSON or missing name → **400**. Unknown connection name → **200** with **success: false** in the JSON body (same semantics as MCP use_connection).

POST /api/connections/use response: JSON with success, active, message, database when applicable (see Response Format).

Not implemented over HTTP: POST /api/connections (register new DSN) — use MCP add_connection when enabled.

Extended endpoints (requires MYSQL_MCP_EXTENDED=1):

MethodEndpointDescription
GET/api/indexes?database=&table=List indexes
GET/api/create-table?database=&table=Show CREATE TABLE
POST/api/explainExplain query
GET/api/views?database=List views
GET/api/triggers?database=List triggers
GET/api/procedures?database=List procedures
GET/api/functions?database=List functions
GET/api/partitions?database=&table=List table partitions
GET/api/size/database?database=Database size
GET/api/size/tables?database=Table sizes
GET/api/foreign-keys?database=Foreign keys
GET/api/status?pattern=Server status
GET/api/variables?pattern=Server variables
GET/api/audit-log?lines=Tail lines from the MCP audit log (JSON). Listed only when extended **and** **MYSQL_MCP_READ_AUDIT_TOOL=1** with **MYSQL_MCP_AUDIT_LOG** configured.
GET/api/slow-log?limit=Slow query log rows or file/table settings. Listed only when extended **and** **MYSQL_MCP_SLOW_QUERY_TOOL=1**.
GET/api/processlistActive MySQL threads (SHOW FULL PROCESSLIST). Listed only when extended **and** **MYSQL_MCP_PROCESS_ADMIN=1**. Requires MySQL **PROCESS** (or equivalent) to succeed.
POST/api/killCancel the **current statement** on a connection: JSON body {"id": <positive integer>} (same id as **/api/processlist**). Executes **KILL QUERY**—the client connection stays open. Listed only when extended **and** **MYSQL_MCP_PROCESS_ADMIN=1**. Requires privilege to run **KILL QUERY** for that thread (e.g. **CONNECTION_ADMIN** or **PROCESS** as applicable).

Vector endpoints (requires MYSQL_MCP_VECTOR=1):

MethodEndpointDescription
POST/api/vector/searchVector similarity search
GET/api/vector/info?database=Vector column info

Token metrics (HTTP mode; /status defaults on when MYSQL_MCP_HTTP is set—use MYSQL_MCP_TOKEN_CARD=0 to hide it; YAML features.token_card applies when not using that default):

MethodEndpointDescription
GET/api/metrics/tokensCumulative token usage, cost estimate, recent queries (always registered; zeros when tracking off)
GET/statusLive HTML dashboard (auto-refresh); listed in GET /api when the feature is enabled

Claude Desktop Integration

Edit your Claude Desktop configuration file:

macOS:

~/Library/Application Support/Claude/claude_desktop_config.json

Windows:

%APPDATA%\Claude\claude_desktop_config.json

Linux:

~/.config/Claude/claude_desktop_config.json

Add:

{
  "mcpServers": {
    "mysql": {
      "command": "mysql-mcp-server",
      "env": {
        "MYSQL_DSN": "user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true",
        "MYSQL_MAX_ROWS": "200",
        "MYSQL_MCP_EXTENDED": "1"
      }
    }
  }
}
Note: If Claude Desktop cannot find the binary, replace "mysql-mcp-server" with the full path from which mysql-mcp-server.

Token dashboard (/status) in the same process as MCP: stdio MCP does not open HTTP by default. Set MYSQL_MCP_METRICS_HTTP=1 so this instance also listens on MYSQL_HTTP_PORT (default 9306) for http://127.0.0.1:9306/status and /api/metrics/tokens — the same counters as Claude’s tool calls. Use MYSQL_MCP_TOKEN_TRACKING=1 so the dashboard is meaningful. Do not set MYSQL_MCP_HTTP=1 here (that mode replaces MCP with full REST only).

"env": {
  "MYSQL_DSN": "user:password@tcp(127.0.0.1:3306)/mydb?parseTime=true",
  "MYSQL_MCP_TOKEN_TRACKING": "1",
  "MYSQL_MCP_METRICS_HTTP": "1",
  "MYSQL_HTTP_PORT": "9306"
}

Restart Claude Desktop.

Cursor IDE Integration

Cursor IDE supports the Model Context Protocol (MCP). Configure it to use mysql-mcp-server:

Edit your Cursor MCP configuration file:

macOS:

~/.cursor/mcp.json

Windows:

%APPDATA%\Cursor\mcp.json

Linux:

~/.config/Cursor/mcp.json

Add:

{
  "mcpServers": {
    "mysql": {
      "command": "mysql-mcp-server",
      "env": {
        "MYSQL_DSN": "root:password@tcp(127.0.0.1:3306)/mydb?parseTime=true",
        "MYSQL_MAX_ROWS": "200",
        "MYSQL_MCP_EXTENDED": "1"
      }
    }
  }
}

Token dashboard (/status) in the same process as MCP: Same behavior as Claude Desktop — stdio MCP does not open HTTP by default. Set MYSQL_MCP_TOKEN_TRACKING=1, MYSQL_MCP_METRICS_HTTP=1, and MYSQL_HTTP_PORT (default 9306) for http://127.0.0.1:9306/status and /api/metrics/tokens. Do not set MYSQL_MCP_HTTP=1 here (full REST replaces stdio MCP).

"env": {
  "MYSQL_DSN": "root:password@tcp(127.0.0.1:3306)/mydb?parseTime=true",
  "MYSQL_MAX_ROWS": "200",
  "MYSQL_MCP_EXTENDED": "1",
  "MYSQL_MCP_TOKEN_TRACKING": "1",
  "MYSQL_MCP_METRICS_HTTP": "1",
  "MYSQL_HTTP_PORT": "9306"
}

Restart Cursor after editing mcp.json.

With Docker:

{
  "mcpServers": {
    "mysql": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "MYSQL_DSN=root:password@tcp(host.docker.internal:3306)/mydb?parseTime=true",
        "-e", "MYSQL_MCP_EXTENDED=1",
        "ghcr.io/askdba/mysql-mcp-server:latest"
      ]
    }
  }
}

Restart Cursor after saving the configuration.

Claude Code Integration

Claude Code supports MCP servers via the CLI or a project-scoped .mcp.json file.

Integration Tests

Integration tests run against real MySQL instances using Docker Compose.

Test against MySQL 8.0 (default):

make test-integration-80

Test against MySQL 8.4:

make test-integration-84

Test against MySQL 9.0:

make test-integration-90

Test against all supported versions (MySQL & MariaDB):

make test-integration-all

Test specifically against MariaDB 11.4:

make test-integration-mariadb-11

ChatGPT Custom GPT Integration

  1. Start the REST API server on a publicly accessible host
  2. Create a Custom GPT with Actions
  3. Import the OpenAPI schema from /api
  4. Configure authentication if needed
🇨🇳 中文文档镜像 AI 翻译 2026-06-05
英文原文章节由系统翻译为中文摘要,便于快速理解。完整原文见上方 "📑 README 深度解析"。
📌 简介

MySQL MCP 服务是一个快速、可扩展的 MySQL 服务,支持多个 MySQL 或 MariaDB 实例,提供多种功能,包括向量搜索、MCP 工具等。

⚡ 功能介绍

MySQL MCP 服务的功能包括:只读模式、多 DSN 支持、MariaDB 支持、向量搜索、MCP 工具等。

📋 环境依赖

MySQL MCP 服务需要 Go 1.24+、Docker 和 Docker Compose、MySQL 客户端等环境依赖。

🛠 安装步骤(Docker/pip/源码)

可以通过 Docker、源码安装 MySQL MCP 服务,具体步骤包括:下载 Docker 镜像、编译源码等。

🚀 使用教程

使用 MySQL MCP 服务,需要配置环境变量、启用 HTTP REST API 模式等,具体步骤包括:配置环境变量、启用 HTTP REST API 模式、使用 MCP 工具等。

⚙️ 配置说明(含 MCP / env)

MySQL MCP 服务的配置包括:环境变量、MCP 参数、HTTP 端口等,具体配置包括:配置环境变量、设置 MCP 参数、配置 HTTP 端口等。

🔌 API 说明

MySQL MCP 服务提供 REST API 模式,支持多种 API 端点,包括:发现端点、数据库端点、查询端点等。

🔄 工作流/模块

MySQL MCP 服务支持多种集成,包括:Claude Desktop 集成、Cursor IDE 集成、Claude Code 集成等,具体步骤包括:配置环境变量、启用集成模式、使用集成工具等。

🎯 aiskill88 AI 点评 A 级 2026-06-05

高质量的MCP工具实现

📚 实用指南(长尾问题)
适合谁
  • 使用 Cursor 编辑器、希望提升 AI 编程效率的开发者
  • 需要让 Claude / Cursor 操作本地工具的 AI 工程师
  • 构建企业知识库 / RAG 检索应用的团队
最佳实践
  • 配置 MCP 服务器时建议使用 stdio 传输 + JSON-RPC,避免暴露公网
  • 生产部署优先使用 Docker Compose 隔离依赖,并挂载 volume 持久化数据
  • Cursor rules 控制在 80 行内,否则模型上下文成本会显著上升
常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • MCP 配置路径拼错或权限不足,重启 Claude Desktop 才生效
  • 容器内无法访问宿主机 localhost — 使用 host.docker.internal
部署方案
  • Docker:mysql-mcp-server 提供官方镜像,docker compose up 一键启动
  • CLI:直接 npm install -g / pip install,命令行调用
  • 云端托管:可放在 Vercel / Railway / Fly.io 等 PaaS 平台
相关搜索
mysql-mcp-server 中文教程mysql-mcp-server 安装报错怎么办mysql-mcp-server MCP 配置mysql-mcp-server Docker 部署mysql-mcp-server 与同类工具对比mysql-mcp-server 最佳实践mysql-mcp-server 适合谁用

⚡ 核心功能

👥 适合谁
  • 使用 Cursor 编辑器、希望提升 AI 编程效率的开发者
  • 需要让 Claude / Cursor 操作本地工具的 AI 工程师
  • 构建企业知识库 / RAG 检索应用的团队
⭐ 最佳实践
  • 配置 MCP 服务器时建议使用 stdio 传输 + JSON-RPC,避免暴露公网
  • 生产部署优先使用 Docker Compose 隔离依赖,并挂载 volume 持久化数据
  • Cursor rules 控制在 80 行内,否则模型上下文成本会显著上升
⚠️ 常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • MCP 配置路径拼错或权限不足,重启 Claude Desktop 才生效
  • 容器内无法访问宿主机 localhost — 使用 host.docker.internal

👥 适合人群

Claude Desktop / Claude Code 用户AI 工具开发者需要扩展 AI 能力的专业人士自动化工程师

🎯 使用场景

  • 在 Claude Desktop 对话中直接调用本地工具,实现 AI 与系统的深度联动
  • 通过自然语言驱动复杂的多步骤自动化任务,代替繁琐手动操作
  • 将多个 MCP 工具组合使用,构建个人专属 AI 工作站

⚖️ 优点与不足

✅ 优点
  • +标准化 MCP 协议,生态互联性强
  • +与 Claude 官方生态无缝对接
  • +即插即用,配置简单快捷
⚠️ 不足
  • 依赖 Claude 客户端,非 Claude 用户无法使用
  • MCP 协议仍在持续演进,接口可能变更
  • 需要一定的配置步骤
⚠️ 使用须知

该工具使用 NOASSERTION 协议,商用场景请仔细阅读协议条款,必要时咨询法律意见。

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

📄 NOASSERTION — 请查阅原始协议条款了解具体使用限制。

🔗 相关工具推荐

📚 相关教程推荐
📰 相关 AI 新闻
🍿 AI 圈相关吃瓜
🗺️ 相关解决方案
🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合

❓ 常见问题 FAQ

mysql-mcp-server 是一款Go开发的AI辅助工具。开源MCP工具:MySQL Server implementation for Model Context Protocol (MCP) written in Go.。⭐35 · Go 主要应用场景包括:MCP协议的MySQL服务器实现。
💡 AI Skill Hub 点评

AI Skill Hub 点评:MCP MySQL 服务器 的核心功能完整,质量良好。对于Claude Desktop / Claude Code 用户来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。

⬇️ 获取与下载
📚 深入学习 MCP MySQL 服务器
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 mysql-mcp-server
原始描述 开源MCP工具:MySQL Server implementation for Model Context Protocol (MCP) written in Go.。⭐35 · Go
Topics mcpgomysql
GitHub https://github.com/askdba/mysql-mcp-server
License NOASSERTION
语言 Go
🔗 原始来源
🐙 GitHub 仓库  https://github.com/askdba/mysql-mcp-server

收录时间:2026-06-05 · 更新时间:2026-06-06 · License:NOASSERTION · AI Skill Hub 不对第三方内容的准确性作法律背书。