MySQL MCP 服务器
用于与 MySQL 数据库交互的 MCP 服务器。
该服务器支持执行只读查询(query)和最终回滚的写查询(test_execute)。
设置
环境变量
将以下环境变量添加到~/.mcp/.env
:
注意:
host.docker.internal
是一个特殊的 DNS 名称,用于从 Docker 容器访问主机服务。连接到主机上运行的 MySQL 服务器时请使用此设置。如果连接到其他 MySQL 服务器,请更改为相应的主机名。
mcp.json 配置
用法
启动服务器
注意:如果您使用的是 OrbStack,则会自动支持
host.docker.internal
,因此可以省略--add-host
选项。虽然 Docker Desktop 通常也自动支持此功能,但为了获得更好的可靠性,建议添加--add-host
选项。
可用命令
1.执行只读查询
回复:
2.测试查询执行
回复:
3. 列出表格
回复:
4.描述表
回复:
实现细节
- 使用 TypeScript 实现
- 使用 mysql2 包
- 作为 Docker 容器运行
- 通过标准输入接受 JSON 命令
- 通过标准输出返回 JSON 响应
- 使用
host.docker.internal
连接到主机 MySQL(兼容 OrbStack 和 Docker Desktop)
安全注意事项
- 使用环境变量进行敏感信息管理
- 预防 SQL 注入是实施者的责任
- 生产使用需要正确的网络配置
- 连接主机服务时需要适当的防火墙设置
You must be authenticated.
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
可以通过 JSON 命令与 MySQL 数据库交互,支持只读查询、写入查询的测试执行以及通过 Docker 检索表信息。
Related Resources
Related MCP Servers
- -securityFlicense-qualityFacilitates interaction with a local MySQL database via a RESTful API, supporting database queries and real-time updates with integration for Cursor MCP services.Last updated -2JavaScript
- -securityAlicense-qualityA Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.Last updated -5,426MIT License
- -securityFlicense-qualityEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.Last updated -Python
- -security-license-qualityAn MCP server that allows working with MySQL databases by providing tools for executing read-only SQL queries, getting table schemas, and listing database tables.Last updated -1JavaScript