About MySQL
MySQL is a standalone MCP server for interacting with MySQL databases, aimed at users who want database tools without a Node.js or Python runtime. It offers CRUD and schema operations, with optional read-only mode and EXPLAIN checks.
Key features
- 01Standalone executable without Node.js or Python
- 02Read and modify database records
- 03Create, alter, describe, and drop tables
- 04Restrict tools with read-only mode
- 05Optionally check queries with EXPLAIN
Use cases
- 01Run SELECT queries against MySQL
- 02Manage database tables through tools
- 03Allow database inspection without writes
- 04Check query plans before CRUD operations
MCP support
It exposes MySQL database and table operations as tools for MCP clients, including query and schema management.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEmysql-mcp-server
特性
- 零依赖:无需 Node.js 或 Python 环境,单一可执行文件
- 安全可靠:支持只读模式,防止意外写入操作
- 查询优化:可选的 EXPLAIN 检查,优化查询性能
- 完整 CRUD:支持数据库和表的完整生命周期管理
- 高性能:基于 Go 语言开发,性能卓越
- 易于使用:支持命令行参数和 DSN 两种配置方式
注意:本项目正在积极开发中,建议在生产环境使用前进行充分测试。
安装
方式一:下载预编译二进制文件
从 Releases 页面 下载适合您操作系统的最新版本,并将其放入 $PATH 或您可以轻松访问的位置。
方式二:从源码构建
如果您已安装 Go 1.21 或更高版本:
go install -v github.com/pengcunfu/mysql-mcp-server@latest
快速开始
配置方式 A:使用命令行参数
{
"mcpServers": {
"mysql": {
"command": "mysql-mcp-server",
"args": [
"--host", "localhost",
"--user", "root",
"--pass", "password",
"--port", "3306",
"--db", "mydb"
]
}
}
}
配置方式 B:使用 DSN 连接字符串
{
"mcpServers": {
"mysql": {
"command": "mysql-mcp-server",
"args": [
"--dsn", "username:password@tcp(localhost:3306)/mydb?parseTime=true&loc=Local"
]
}
}
}
提示:更多 MySQL DSN 配置选项请参考 MySQL DSN 文档。
使用绝对路径
如果二进制文件不在 $PATH 中,需要使用完整路径。例如,Windows 用户可以这样配置:
{
"mcpServers": {
"mysql": {
"command": "C:\\Users\\<username>\\Downloads\\mysql-mcp-server.exe",
"args": ["--host", "localhost", "--user", "root", "--pass", "password"]
}
}
}
配置选项
命令行参数
| 标志 | 说明 | 默认值 |
|---|---|---|
--host | MySQL 主机名 | localhost |
--user | MySQL 用户名 | root |
--pass | MySQL 密码 | - |
--port | MySQL 端口 | 3306 |
--db | 数据库名 | - |
--dsn | 自定义 DSN(优先使用) | - |
--read-only | 启用只读模式 | false |
--with-explain-check | 执行前使用 EXPLAIN 检查查询计划 | false |
可选标志
| 标志 | 说明 |
|---|---|
--read-only | 启用只读模式,仅允许 list、read_ 和 desc_ 开头的工具,防止数据修改 |
--with-explain-check | 在执行 CRUD 查询前使用 EXPLAIN 检查查询计划,帮助优化性能 |
注意:修改标志后需要重启 MCP 服务器才能生效
可用工具
数据库模式管理
list_table
列出数据库服务器中的所有表。
- 参数:无
- 返回:表的名称列表
create_table
在数据库服务器中创建新表。
- 参数:
query:CREATE TABLE SQL 语句
- 返回:受影响的行数
alter_table
修改现有表结构,不支持删除表或列。
- 参数:
query:ALTER TABLE SQL 语句
- 返回:受影响的行数
desc_table
查看表结构详情。
- 参数:
name:表名
- 返回:表的结构信息(CREATE TABLE 语句)
drop_table
删除数据库服务器中的表。
- 参数:
name:表名
- 返回:执行结果
数据操作
read_query
执行只读 SQL 查询(SELECT)。
- 参数:
query:SELECT SQL 语句
- 返回:查询结果集(CSV 格式)
write_query
执行写入 SQL 查询(INSERT)。
- 参数:
query:INSERT SQL 语句
- 返回:受影响的行数和最后插入的 ID
update_query
执行更新 SQL 查询(UPDATE)。
- 参数:
query:UPDATE SQL 语句
- 返回:受影响的行数
delete_query
执行删除 SQL 查询(DELETE)。
- 参数:
query:DELETE SQL 语句
- 返回:受影响的行数
贡献
欢迎贡献!如果您有任何想法、建议或发现了 bug,请:
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启一个 Pull Request
许可证
本项目采用 Apache License 2.0 许可证。
相关链接
作者
pengcunfu
- GitHub: @pengcunfu
如果这个项目对您有帮助,请给它一个 star!
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.