MySQL MCP Server
Provides tools for interacting with MySQL databases, including listing databases and tables, inspecting table columns and indexes, viewing views and functions, and creating or altering tables.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MySQL MCP ServerCan you list all tables in the analytics database?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MySQL MCP Server 安全版
一个基于 Model Context Protocol (MCP) 的 MySQL 数据库管理工具,提供了一系列用于与 MySQL 数据库交互的工具。
功能特性
🔌 数据库连接管理 - 自动管理 MySQL 数据库连接
📊 数据库信息查询 - 获取数据库列表、表信息、视图、函数等
🔍 表结构分析 - 查看表字段、索引等结构信息
✏️ 表结构操作 - 支持创建新表、修改表结构(添加/修改字段)
🐳 Docker 部署支持 - 提供 Dockerfile 和 docker-compose 配置
Related MCP server: mysql-mcp-server
MCP 工具
工具名称 | 功能描述 |
| 获取所有数据库列表 |
| 获取指定数据库中的所有表 |
| 获取指定表的字段信息 |
| 获取指定表的索引信息 |
| 获取指定数据库中的所有视图 |
| 获取指定数据库中的所有函数 |
| 在指定数据库中创建新表 |
| 修改数据表字段 |
安装部署
环境要求
Python 3.12+
MySQL 5.7+ / 8.0+
pip
本地安装
克隆项目并进入目录:
git clone https://gitee.com/MZ11/mcp_mysql.git
cd mcp_mysql安装依赖:
pip install -r requirements.txt配置数据库连接(复制
.env.example为.env并修改):
cp .env.example .env
# 编辑 .env 文件,填入数据库连接信息运行服务:
python main.pyDocker 部署
构建镜像:
docker build -t mcp_mysql .运行容器:
docker run -p 8991:8991 mcp_mysql
# 注意 拼接数据库相关参数 或使用 docker-compose:
docker-compose up -d
#注意:修改 `docker-compose.yml` 文件中的 数据库配置信息配置说明
在 .env 文件中配置数据库连接信息:
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password使用示例
TRAE、Qorde开发工具使用MCP服务
设置 >> MCP >> 手动配置
{
"mcpServers": {
"mysql_mcp": {
"url": "http://yourhost:8991/sse"
}
}
}获取所有数据库
# 调用 MCP 工具
result = get_databases()获取指定表的字段信息
# 获取 mysql 数据库中 user 表的字段信息
columns = get_columns(database_name="mysql", table_name="user")创建新表
# 在 test_db 中创建新表
create_table(
database_name="test_db",
table_name="users",
columns="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), email VARCHAR(100)"
)修改表结构
# 在 users 表中添加 age 字段
alter_table(
database_name="test_db",
table_name="users",
action="add",
column_name="age",
column_definition="INT"
)项目结构
mcp_mysql/
├── main.py # MCP 服务器主程序
├── requirements.txt # Python 依赖
├── Dockerfile # Docker 镜像构建文件
├── docker-compose.yml # Docker Compose 配置
├── .env.example # 环境变量示例
└── README.md # 项目说明文档许可证
本项目遵循开源协议。
Related MCP Connectors
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted MCP server for AI-driven data ops. Create apps, manage schemas, and CRUD structured data.
List, read, edit, and deploy your GenMB AI-generated apps from any MCP client.
The Instant MCP server is a wrapper around the Instant Platform SDK that enables creating, managing, and updating InstantDB applications directly within an editor. It provides tools for fetching rules files for LLMs, retrieving and pushing app schemas, managing permission rules, and executing database queries. Key capabilities include schema management (get-schema, push-schema), permission management (get-perms, push-perms), query execution, and listing recent query history.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.133 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables MySQL database operations through MCP, including executing SQL queries, listing databases and tables, and describing table structures.362 npm5MIT
- AlicenseNot gradedqualityDmaintenanceEnables natural language interaction with MySQL databases through MCP, supporting SQL execution, schema exploration, and database management via tools, resources, and prompts.5MIT
- AlicenseNot gradedqualityCmaintenanceProvides MySQL database operations through MCP, enabling users to execute SQL queries, retrieve table structures, and check database connectivity using natural language.133 npmApache 2.0