MCP MySQL Server

MCP MySQL Server

Enables secure read-only access to MySQL databases through SELECT queries via HTTP SSE interface. Provides safe database exploration and data retrieval with configurable timeout settings.

Category
Visit Server

README

MCP MySQL Server

一个用于连接和查询MySQL数据库的MCP (Model Context Protocol) 服务器。

功能特性

  • 通过 SSE (Server-Sent Events) 提供 HTTP 接口
  • 连接MySQL数据库
  • 执行 SELECT 查询(只读访问)
  • 安全的只读模式,不支持 INSERT/UPDATE/DELETE 操作

安装

使用 uv(推荐)

# 安装 uv(如果尚未安装)
pip install uv

# 创建虚拟环境
uv venv

# 激活虚拟环境
.venv\Scripts\activate  # Windows
# source .venv/bin/activate  # MacOS/Linux

# 安装项目
pip install -e .

使用 pip

# 创建虚拟环境
python -m venv venv
.\venv\Scripts\activate  # Windows
# source venv/bin/activate  # MacOS/Linux

# 安装项目
pip install -e .

使用方法

启动服务器

# 设置环境变量
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=your_username
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export QUERY_TIMEOUT=30  # 查询超时时间(秒)

# Windows PowerShell
$env:MYSQL_HOST="localhost"
$env:MYSQL_PORT="3306"
$env:MYSQL_USER="your_username"
$env:MYSQL_PASSWORD="your_password"
$env:MYSQL_DATABASE="your_database"
$env:QUERY_TIMEOUT="30"  # 查询超时时间(秒)

# 启动 SSE 服务器
python -m mcp_mysql.server
# 或
mcp-mysql

# 服务器将运行在 http://localhost:8000

配置参数

环境变量:

  • MYSQL_HOST - MySQL 服务器地址(默认: localhost)
  • MYSQL_PORT - MySQL 端口(默认: 3306)
  • MYSQL_USER - 数据库用户名(默认: root)
  • MYSQL_PASSWORD - 数据库密码(默认: 空)
  • MYSQL_DATABASE - 数据库名称(默认: 空)
  • QUERY_TIMEOUT - 查询超时时间,单位秒(默认: 30)
  • MCP_HOST - MCP 服务器地址(默认: 0.0.0.0)
  • MCP_PORT - MCP 服务器端口(默认: 8000)

在 Claude Desktop 中配置

在 Claude Desktop 配置文件中添加以下配置:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "mysql": {
      "url": "http://localhost:8000/sse"
    }
  }
}

可用工具

  1. query - 执行 SELECT 查询
    • sql: 要执行的 SELECT 语句(仅支持 SELECT 查询,保证只读访问)

示例

连接后,你可以:

  • "查询 users 表的所有数据:SELECT * FROM users"
  • "查询特定条件:SELECT name, email FROM users WHERE id > 10"
  • "统计数据:SELECT COUNT(*) FROM orders WHERE status='completed'"

注意: 为了数据安全,本服务器只支持 SELECT 查询,不支持 INSERT、UPDATE、DELETE 等写操作。

安全注意事项

  • 请妥善保管数据库凭据
  • 建议使用只读账户
  • 不要在公共仓库中提交包含密码的配置文件

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured