MySQL Query MCP Server
MySQL 查询 MCP 服务器
模型上下文协议 (MCP) 服务器,为 AI 助手提供只读MySQL 数据库查询。您可以直接使用 AI 工具执行查询、探索数据库结构并调查数据。
支持的AI工具
该 MCP 服务器可与任何支持模型上下文协议的工具配合使用,包括:
Cursor IDE : 在
.cursor/mcp.json中设置Anthropic Claude :与兼容的 MCP 客户端一起使用
其他兼容 MCP 的 AI 助手:请遵循工具的 MCP 配置说明
Related MCP server: MCP Server for MySQL
功能与限制
它的作用
✅ 执行只读MySQL 查询(仅限 SELECT、SHOW、DESCRIBE)
✅ 使用预定义环境(本地、开发、暂存、生产)
✅ 提供数据库信息和元数据
✅ 列出可用的数据库环境
✅ 支持 SSL 连接以实现安全的数据库访问
✅ 实现查询超时以防止长时间运行的操作
它不能做什么
❌执行写操作(INSERT、UPDATE、DELETE、CREATE、ALTER 等)
❌支持自定义环境名称(限于本地、开发、暂存、生产)
❌ 提供数据库设计或模式生成功能
❌ 充当完整的数据库管理工具
此工具专为通过只读查询进行数据调查和探索而设计。它不适用于数据库管理、架构管理或数据修改。

快速安装
# Install globally with npm
npm install -g mysql-query-mcp-server
# Or run directly with npx
npx mysql-query-mcp-server设置说明
配置您的 AI 工具以使用 MCP 服务器
创建或编辑您的 MCP 配置文件(例如,Cursor IDE 的.cursor/mcp.json ):
基本配置:
{
"mysql": {
"name": "MySQL Query MCP",
"description": "MySQL read-only query access through MCP",
"type": "bin",
"enabled": true,
"bin": "mysql-query-mcp"
}
}具有数据库凭证的综合配置:
{
"mysql": {
"command": "npx",
"args": ["mysql-query-mcp-server@latest"],
"env": {
"LOCAL_DB_HOST": "localhost",
"LOCAL_DB_USER": "root",
"LOCAL_DB_PASS": "<YOUR_LOCAL_DB_PASSWORD>",
"LOCAL_DB_NAME": "your_database",
"LOCAL_DB_PORT": "3306",
"DEVELOPMENT_DB_HOST": "dev.example.com",
"DEVELOPMENT_DB_USER": "<DEV_USER>",
"DEVELOPMENT_DB_PASS": "<DEV_PASSWORD>",
"DEVELOPMENT_DB_NAME": "your_database",
"DEVELOPMENT_DB_PORT": "3306",
"STAGING_DB_HOST": "staging.example.com",
"STAGING_DB_USER": "<STAGING_USER>",
"STAGING_DB_PASS": "<STAGING_PASSWORD>",
"STAGING_DB_NAME": "your_database",
"STAGING_DB_PORT": "3306",
"PRODUCTION_DB_HOST": "prod.example.com",
"PRODUCTION_DB_USER": "<PRODUCTION_USER>",
"PRODUCTION_DB_PASS": "<PRODUCTION_PASSWORD>",
"PRODUCTION_DB_NAME": "your_database",
"PRODUCTION_DB_PORT": "3306",
"DEBUG": "false",
"MCP_MYSQL_SSL": "true",
"MCP_MYSQL_REJECT_UNAUTHORIZED": "false"
}
}
}选择正确的配置方法
有两种方法可以配置 MySQL MCP 服务器:
二进制配置(
type: "bin",bin: "mysql-query-mcp")何时使用:当您全局安装软件包时(
npm install -g mysql-query-mcp-server)优点:配置更简单
缺点:需要全局安装
命令配置(
command: "npx",args: ["mysql-query-mcp-server@latest"])何时使用:当您想使用最新版本而不进行全局安装时
优点:无需全局安装,所有配置都在一个文件中
缺点:配置更复杂
选择最适合您工作流程的方法。这两种方法均可与任何支持 MCP 的 AI 助手完美兼容。
重要配置说明
您必须使用完整的环境名称:LOCAL_、DEVELOPMENT_、STAGING_、PRODUCTION_
DEV_ 或 PROD_ 等缩写不起作用
DEBUG、MCP_MYSQL_SSL 等全局设置适用于所有环境
必须配置至少一个环境(通常是“本地”)
您只需配置您计划使用的环境
出于安全原因,请考虑使用环境变量或安全凭证存储来存储生产凭证
配置选项
环境变量 | 描述 | 默认 |
调试 | 启用调试日志记录 | 错误的 |
[环境]_DB_HOST | 环境的数据库主机 | - |
[环境]_DB_USER | 数据库用户名 | - |
[环境]_DB_PASS | 数据库密码 | - |
[环境]数据库名称 | 数据库名称 | - |
[环境]_DB_PORT | 数据库端口 | 3306 |
[环境]_DB_SSL | 启用 SSL 连接 | 错误的 |
MCP_MYSQL_SSL | 为所有连接启用 SSL | 错误的 |
MCP_MYSQL_REJECT_UNAUTHORIZED | 验证 SSL 证书 | 真的 |
与人工智能助手集成
您的 AI 助手可以通过 MCP 服务器与 MySQL 数据库进行交互。以下是一些示例:
示例查询:
Can you use the query tool to show me the first 10 users from the database? Use the local environment.I need to analyze our sales data. Can you run a SQL query to get the total sales per region for last month from the development database?Can you use the info tool to check what tables are available in the staging database?Can you list all the available database environments we have configured?使用 MySQL MCP 工具
MySQL Query MCP 服务器提供了三个主要工具供您的 AI 助手使用:
1. 查询
针对特定环境执行只读 SQL 查询:
Use the query tool to run:
SELECT * FROM customers WHERE signup_date > '2023-01-01' LIMIT 10;
on the development environment2. 信息
获取有关数据库的详细信息:
Use the info tool to check the status of our production database.3. 环境
列出配置中所有已配置的环境:
Use the environments tool to show me which database environments are available.可用工具
MySQL Query MCP 服务器提供了三个主要工具:
1. 查询
执行只读 SQL 查询:
-- Example query to run with the query tool
SELECT * FROM users LIMIT 10;支持的查询类型(严格限制为) :
SELECT 语句
SHOW 命令
DESCRIBE/DESC 表
2. 信息
获取有关数据库的详细信息:
服务器版本
连接状态
数据库变量
进程列表
可用数据库
3. 环境
列出配置中所有已配置的环境:
Use the environments tool to show me which database environments are available.安全注意事项
✅ 只允许只读查询(SELECT、SHOW、DESCRIBE)
✅ 每个环境都有自己独立的连接池
✅ 生产环境支持 SSL 连接
✅ 查询超时可防止失控操作
⚠️考虑使用安全凭证管理来管理数据库凭证
故障排除
连接问题
如果您在连接时遇到问题:
在 MCP 配置中验证数据库凭据
确保 MySQL 服务器正在运行并且可以访问
检查防火墙规则是否阻止连接
通过在配置中设置 DEBUG=true 来启用调试模式
常见错误
错误:环境没有可用的连接池
确保已为该环境定义了所有必需的环境变量
检查您是否正在使用受支持的环境名称之一(本地、开发、暂存、生产)
错误:查询执行失败
验证 SQL 语法
检查您是否仅使用受支持的查询类型(SELECT、SHOW、DESCRIBE)
确保您的查询确实是只读的
有关更全面的故障排除,请参阅故障排除指南。
有关如何与 AI 助手集成的示例,请参阅集成示例。
有关 MCP 协议的实现细节,请参阅MCP README 。
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
CI/CD 和发布流程
该项目使用 GitHub Actions 进行持续集成和自动发布。
CI/CD 工作流程
CI/CD 管道包括:
构建和测试:在每次推送到
main和develop分支时运行,并在对这些分支的拉取请求时运行使用 Node.js 16.x 和 18.x 测试代码库
确保包正确构建
验证所有测试通过
发布:当更改被推送到
main分支并且构建/测试作业成功时运行使用
release-please来管理版本升级和变更日志更新根据常规提交创建包含版本变更的发布 PR
合并发布 PR 时自动发布到 npm
发布流程
该项目遵循语义版本控制:
主要版本:重大变更(不向后兼容)
次要版本:新功能(向后兼容)
补丁版本:错误修复和小改进
提交应遵循常规提交格式:
feat: add new feature- 小版本升级fix: resolve bug- 补丁版本升级docs: update documentation- 无版本升级chore: update dependencies- 无版本升级BREAKING CHANGE: change API- 主要版本升级
当您推送到main时, release-please将分析提交并自动创建或更新具有适当版本提升和变更日志条目的发布 PR。
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
作者
Abou Koné - 工程主管兼首席技术官
如需更多信息或支持,请在 GitHub 存储库上打开一个问题。
Available Tools
3 toolsenvironmentsA
List available MySQL database environments
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description clearly indicates a read-only listing operation with no side effects. With no annotations provided, this straightforward disclosure is sufficient.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, well-structured sentence with no unnecessary words. It is front-loaded with the action and resource.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (no parameters, no output schema), the description adequately explains its purpose. It could optionally hint at the format of the list, but not required.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has no parameters, so schema coverage is 100%. The description adds no parameter info, but none is needed; baseline score for zero parameters is 4.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses the specific verb 'List' and clearly identifies the resource as 'available MySQL database environments'. It distinguishes from sibling tools 'info' and 'query' by implying this is a listing operation.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies use when the agent needs to see available environments before running queries or getting info, but does not explicitly state when to use or avoid this tool relative to siblings.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
infoC
Get information about MySQL databases
| Name | Required | Description | Default |
|---|---|---|---|
| environment | Yes | Target environment to get information from |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, and the description only implies a read operation ('Get information') without explicit statements about safety or side effects. It fails to disclose any behavioral traits beyond the basic action.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence, no wasted words, and appropriately sized for a simple tool. It is front-loaded with the core action.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the absence of an output schema and the tool's simple nature, the description is too minimal. It does not specify what kind of information is returned or any additional context, leaving the agent underinformed.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema provides 100% coverage with a description for the 'environment' parameter. The tool description adds no additional semantics beyond what is in the schema, earning the baseline score.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states 'Get information about MySQL databases,' specifying the verb and resource. However, it does not differentiate from siblings like 'query', which might also retrieve data.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance on when to use this tool versus alternatives like 'query' or 'environments'. The description does not provide context or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
queryA
Execute read-only SQL queries against MySQL databases
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query to execute (SELECT and SHOW only) | |
| timeout | No | Query timeout in milliseconds (default: 30000) | |
| environment | Yes | Target environment to run the query against |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description bears full responsibility. It declares read-only behavior but does not elaborate on error handling, authentication, rate limits, or result limits. The constraint 'SELECT and SHOW only' is only in the schema, not the description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, front-loaded sentence with no superfluous words. It efficiently conveys the tool's purpose.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description lacks details about output format, pagination, or behavior under errors/timeouts. Given no output schema, the agent might need more context. However, for a simple query tool, the description is minimally sufficient.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so all parameters have descriptions. The description adds no extra parameter semantics beyond the schema, which is adequate but not additive.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'Execute', the resource 'SQL queries', and the context 'against MySQL databases', specifying 'read-only'. This distinguishes it well from its siblings 'environments' and 'info'.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implicitly indicates usage for read-only SQL queries but does not explicitly state when to use or avoid it, nor does it mention alternative tools. However, the sibling tools are distinct enough that ambiguity is low.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
3 tool updates
- First observed
environments - First observed
info - First observed
query
TDQS
Each tool serves a distinct purpose: environments lists available databases, info retrieves database metadata, query executes read-only SQL. No overlap in functionality.
All tool names are single lowercase words, which is consistent, but they don't follow a strong verb_noun pattern. Names are clear and unambiguous.
Three tools is ideal for a focused MCP server that provides database environment listing, metadata retrieval, and query execution. No unnecessary tools.
The tool surface covers the core workflow of exploring and querying databases. Missing explicit schema or table listing tools, but info may partially address this.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
The HubSpot MCP Server acts as a bridge that enables AI assistants and Large Language Models to securely interact with HubSpot CRM data through natural conversation, without requiring users to understand complex API structures. It provides read-only access to standard CRM objects (contacts, companies, deals, tickets, products, invoices, and more) and their associations, secured via OAuth 2.0, allowing AI agents to perform tasks like summarizing deals, fetching company updates, and looking up record changes.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.11,0522,108MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server providing read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.131MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.11,052MIT
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.5180MIT
Appeared in Searches
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/devakone/mysql-query-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server