MySQL MCP Server
Enables comprehensive MySQL database management through AI assistants, including database and table operations, data querying, insertion, updates, deletion, and CSV/JSON import/export functionality with built-in SQL injection protection
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 Server show me all tables in the production 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
🎯 让 AI 助手轻松管理 MySQL 数据库的强大 MCP 工具
基于 Model Context Protocol (MCP) 的 MySQL 数据库管理工具,让您能够通过 AI 助手(如 Claude)执行各种数据库操作,无需手动编写 SQL 语句。
✨ 功能特性
🔗 连接管理
✅ 灵活的数据库连接配置
✅ 支持环境变量和参数配置
✅ 连接状态检查和管理
✅ 安全的连接池管理
🗄️ 数据库操作
✅ 列出所有数据库
✅ 创建数据库(支持字符集和排序规则)
✅ 删除数据库
✅ 数据库信息查询
📊 表操作
✅ 列出指定数据库的所有表
✅ 查看表结构和字段详情
✅ 创建表(通过 SQL 语句)
✅ 删除表
✅ 表信息统计
📝 数据操作
✅ 执行 SQL 查询(支持参数化查询)
✅ 插入数据(支持批量插入)
✅ 更新数据
✅ 删除数据
✅ 数据导出到 CSV/JSON 文件
✅ 从 CSV/JSON 文件导入数据
🛡️ 安全特性
✅ SQL 注入防护
✅ 危险操作检测
✅ 参数化查询支持
✅ 权限控制建议
Related MCP server: MySQL MCP Server
📦 安装
方式一:直接使用(推荐)
在您的 MCP 客户端配置中直接使用 @latest 标签:
{
"mcpServers": {
"mysql-mcp": {
"command": "npx",
"args": ["@pickstar-2002/mysql-mcp@latest"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "mysql"
}
}
}
}方式二:全局安装
npm install -g @pickstar-2002/mysql-mcp@latest方式三:项目安装
npm install @pickstar-2002/mysql-mcp@latest🚀 快速开始
1. 配置环境变量
创建 .env 文件:
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=mysql
# 可选配置
MYSQL_CONNECTION_LIMIT=10
MYSQL_TIMEOUT=600002. 在 Claude Desktop 中配置
编辑 Claude Desktop 配置文件:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"mysql-mcp": {
"command": "npx",
"args": ["@pickstar-2002/mysql-mcp@latest"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "mysql"
}
}
}
}3. 在其他 MCP 客户端中配置
对于支持 MCP 协议的其他客户端:
{
"command": "npx",
"args": ["@pickstar-2002/mysql-mcp@latest"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password"
}
}💡 使用示例
配置完成后,您可以在 AI 助手中使用自然语言进行数据库操作:
🔗 连接数据库
请连接到我的 MySQL 数据库,主机是 localhost,用户名是 root📋 查看数据库列表
请列出所有的数据库🆕 创建数据库
请创建一个名为 test_db 的数据库,使用 utf8mb4 字符集🔍 查看表结构
请查看 users 表的结构和字段信息📊 执行查询
请查询 users 表中所有年龄大于 18 的用户,按注册时间排序➕ 插入数据
请向 users 表插入一条新记录:name='张三', age=25, email='zhangsan@example.com'📤 导出数据
请将 users 表的数据导出为 CSV 文件到 /tmp/users.csv📥 导入数据
请从 /tmp/users.csv 文件导入数据到 users 表🛠️ API 工具列表
工具名称 | 功能描述 |
| 连接到 MySQL 数据库 |
| 断开数据库连接 |
| 列出所有数据库 |
| 创建数据库 |
| 删除数据库 |
| 列出表 |
| 查看表结构 |
| 创建表 |
| 删除表 |
| 执行 SQL 查询 |
| 插入数据 |
| 更新数据 |
| 删除数据 |
| 导出数据 |
| 导入数据 |
🔧 配置选项
环境变量
变量名 | 描述 | 默认值 | 必需 |
| MySQL 服务器地址 |
| ✅ |
| MySQL 端口号 |
| ❌ |
| 用户名 |
| ✅ |
| 密码 | - | ✅ |
| 默认数据库 | - | ❌ |
| 连接池大小 |
| ❌ |
| 连接超时时间(ms) |
| ❌ |
🛡️ 安全注意事项
🔐 密码保护: 确保
.env文件不被提交到版本控制系统🚫 SQL 注入防护: 工具内置基础 SQL 安全检查,建议使用参数化查询
👤 权限控制: 建议为 MCP 服务器创建专用 MySQL 用户并限制权限
🌐 网络安全: 生产环境中确保 MySQL 服务器网络访问安全
📝 操作审计: 重要操作前会进行安全提示
🤝 贡献
欢迎提交 Issue 和 Pull Request!
Fork 本项目
创建特性分支 (
git checkout -b feature/AmazingFeature)提交更改 (
git commit -m 'Add some AmazingFeature')推送到分支 (
git push origin feature/AmazingFeature)开启 Pull Request
📄 许可证
本项目基于 MIT License 开源协议。
📞 联系方式
如有问题或建议,欢迎联系:
微信: pickstar_loveXX
⭐ 如果这个项目对您有帮助,请给个 Star 支持一下!
Available Tools
15 toolsmysql_connectC
连接到 MySQL 数据库
Inputs: host (required), user (required), password (required), port, +1 more.
mysql_create_databaseD
创建数据库
Inputs: name (required), charset, collation.
mysql_create_tableD
创建表
Inputs: sql (required).
mysql_deleteC
删除表数据
Inputs: tableName (required), where (required).
mysql_describe_tableC
查看表结构
Inputs: tableName (required), database.
mysql_disconnectB
断开 MySQL 数据库连接
Inputs: no named parameters.
mysql_drop_databaseC
删除数据库
Inputs: name (required).
mysql_drop_tableC
删除表
Inputs: tableName (required).
mysql_export_dataC
导出表数据到文件
Inputs: tableName (required), filePath (required), format (required), where.
mysql_import_dataC
从文件导入数据到表
Inputs: tableName (required), filePath (required), format (required), truncateFirst.
mysql_insertC
插入数据到表
Inputs: tableName (required), data (required).
mysql_list_databasesB
列出所有数据库
Inputs: no named parameters.
mysql_list_tablesB
列出指定数据库的所有表
Inputs: database.
mysql_queryC
执行 SQL 查询
Inputs: sql (required), params.
mysql_updateC
更新表数据
Inputs: tableName (required), data (required), where (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Every tool has a clearly distinct purpose with no ambiguity. Each tool targets a specific MySQL operation (e.g., connect/disconnect, create/drop databases/tables, CRUD operations, import/export, listing), and there is no overlap in functionality that would cause misselection.
All tool names follow a consistent 'mysql_' prefix with a verb_noun pattern (e.g., mysql_connect, mysql_create_database, mysql_list_tables). This predictable naming convention makes it easy for agents to understand and use the tools without confusion.
With 15 tools, the server is well-scoped for MySQL database management. Each tool earns its place by covering essential operations like connection handling, database/table lifecycle, data manipulation, and import/export, without being overly heavy or thin for the domain.
The tool set provides complete CRUD and lifecycle coverage for MySQL operations. It includes connection management, database/table creation/deletion, data insertion/update/delete/query, structure inspection, and import/export functionalities, leaving no obvious gaps for typical database workflows.
Maintenance
Related MCP Connectors
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
Query, explore, and manage your databases through natural conversation.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.-
- AlicenseNot gradedqualityDmaintenanceEnables natural language database operations on MySQL databases with AI integration, supporting CRUD operations, schema inspection, and audit logging with built-in security features including SQL injection protection and permission controls.MIT
- FlicenseNot gradedqualityDmaintenanceEnables management and querying of multiple MySQL databases through natural language, allowing AI assistants to list databases, execute SQL queries, and explore database schemas.1-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely connect to and manage MySQL databases with support for multiple database connections, complete CRUD operations, schema inspection, and dynamic connection management through natural language.15 npm81MIT