Skip to main content
Glama

mysql_mcp_server

by wenb1n-dev

mcp_mysql_服务器

介绍

mcp_mysql_server_pro 不仅涉及 MySQL CRUD 操作,还包括数据库异常分析功能,并方便开发人员使用自定义工具进行扩展。

  • 支持 STDIO 和 SSE 模式
  • 支持多个SQL执行,以“;”分隔
  • 支持根据表注释查询数据库表名和字段
  • 支持SQL执行计划分析
  • 支持中文字段转拼音
  • 支持表锁分析
  • 支持数据库健康状态分析
  • 支持readonly、writer、admin三种角色的权限控制
    "readonly": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN"], # Read-only permissions "writer": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE"], # Read-write permissions "admin": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"] # Administrator permissions
  • 支持提示模板调用

工具清单

工具名称描述
执行sql可以根据权限配置执行["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"]命令的SQL执行工具
获取中文首字母将中文字段名称转换为拼音首字母
获取数据库健康运行状况分析MySQL健康状态(连接状态、事务状态、运行状态、锁状态检测)
获取表描述根据表名查找数据库中的表结构,支持多表查询
获取表索引根据表名查找数据库中的表索引,支持多表查询
获取表锁检查当前MySQL服务器是否存在行级锁或者表级锁
获取表名根据表注释和描述在数据库中搜索表名
获取数据库健康索引使用情况获取当前连接的mysql数据库的索引使用情况,包括冗余索引情况、性能较差的索引情况、查询时间大于30秒的top5个未使用索引情况

提示列表

提示名称描述
分析mysql提示符这是分析 MySQL 相关问题的提示
查询表数据提示这是使用工具查询表数据的提示,如果description为空,则会初始化为MySQL数据库查询助手

使用说明

SSE模式

  • 使用 uv 启动服务

将以下内容添加到您的 mcp 客户端工具中,例如 cursor、cline 等。

mcp json 如下:

{ "mcpServers": { "operateMysql": { "name": "operateMysql", "description": "", "isActive": true, "baseUrl": "http://localhost:9000/sse" } } }

修改 .env 文件内容以使用数据库详细信息更新数据库连接信息:

# MySQL Database Configuration MYSQL_HOST=192.168.xxx.xxx MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=root MYSQL_DATABASE=a_llm MYSQL_ROLE=readonly # Optional, default is 'readonly'. Available values: readonly, writer, admin

启动命令:

# Download dependencies uv sync # Start uv run server.py

STDIO模式

将以下内容添加到您的 mcp 客户端工具中,例如 cursor、cline 等。

mcp json 如下:

{ "mcpServers": { "operateMysql": { "isActive": true, "name": "operateMysql", "command": "uv", "args": [ "--directory", "G:\\python\\mysql_mcp\\src", # Replace this with your project path "run", "server.py", "--stdio" ], "env": { "MYSQL_HOST": "192.168.xxx.xxx", "MYSQL_PORT": "3306", "MYSQL_USER": "root", "MYSQL_PASSWORD": "root", "MYSQL_DATABASE": "a_llm", "MYSQL_ROLE": "readonly" # Optional, default is 'readonly'. Available values: readonly, writer, admin } } } }

自定义工具扩展

  1. 在handles包中添加一个新的工具类,继承自BaseHandler,并实现get_tool_description和run_tool方法
  2. init.py中导入新工具,使其在服务器中可用

示例

  1. 创建新表并插入数据,提示格式如下:
# Task Create an organizational structure table with the following structure: department name, department number, parent department, is valid. # Requirements - Table name: t_admin_rms_zzjg - Field requirements: string type uses 'varchar(255)', integer type uses 'int', float type uses 'float', date and time type uses 'datetime', boolean type uses 'boolean', text type uses 'text', large text type uses 'longtext', large integer type uses 'bigint', large float type uses 'double' - Table header needs to include primary key field, serial number XH varchar(255) - Table must include these fixed fields at the end: creator-CJR varchar(50), creation time-CJSJ datetime, modifier-XGR varchar(50), modification time-XGSJ datetime - Field naming should use tool return content - Common fields need indexes - Each field needs comments, table needs comment - Generate 5 real data records after creation
  1. 根据表comments查询数据,提示如下:
Query Zhang San's data from the user information table
  1. 分析慢SQL,提示如下:
select * from t_jcsjzx_hjkq_cd_xsz_sk xsz left join t_jcsjzx_hjkq_jcd jcd on jcd.cddm = xsz.cddm Based on current index situation, review execution plan and provide optimization suggestions in markdown format, including table index status, execution details, and optimization recommendations
  1. 分析SQL死锁问题,提示如下:
update t_admin_rms_zzjg set sfyx = '0' where xh = '1' is stuck, please analyze the cause
  1. 分析健康状况提示如下
Check the current health status of MySQL

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

增加了对 STDIO 模式和 SSE 模式的支持增加了对多个 SQL 执行的支持,以“;”分隔增加了根据表注释查询数据库表名和字段的功能增加了 SQL 执行计划分析增加了中文字段转拼音的功能

  1. 介绍
    1. 工具清单
      1. 提示列表
        1. 使用说明
          1. SSE模式
          2. STDIO模式
        2. 自定义工具扩展
          1. 示例

            Related MCP Servers

            • -
              security
              A
              license
              -
              quality
              Facilitates interaction with Microsoft SQL Server Express, supporting database operations such as querying, table management, and schema inspection via natural language MCP commands.
              Last updated -
              1
              Python
              MIT License
            • -
              security
              F
              license
              -
              quality
              A server that enables interaction with PostgreSQL, MySQL, MariaDB, or SQLite databases through Claude Desktop using natural language queries.
              Last updated -
              Python
            • -
              security
              F
              license
              -
              quality
              A natural language interface that allows Claude to execute SQL queries on your local MySQL databases, enabling database interaction using natural language.
              Last updated -
              2
              Python
              • Linux
              • Apple
            • -
              security
              F
              license
              -
              quality
              Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
              Last updated -
              Python
              • Linux
              • Apple

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/wenb1n-dev/mysql_mcp_server_pro'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server