MySQL MCP Server
Provides tools for interacting with MariaDB databases, enabling AI agents to query, analyze table structures, get sample data, and execute write operations when enabled.
Provides tools for interacting with MySQL databases, enabling AI agents to query, analyze table structures, get sample data, and execute write operations when enabled.
Click on "Install 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 Serverlist all tables in the current 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/MariaDB数据库
✨ 特性
🔒 安全优先 — 默认只读模式,写操作需显式开启
📊 智能分析 — 表结构、统计信息、执行计划一键获取
🇨🇳 中文优先 — 文档、错误提示、注释全部中文化
🔌 即插即用 — 支持Claude Desktop、Cursor、Cline等MCP客户端
🛡️ 访问控制 — 可配置允许的数据库和禁止的表
🔄 连接池 — 自动管理数据库连接,高效复用
Related MCP server: MCP MySQL Server
🚀 快速开始
安装
pip install mysql-mcp-server配置
在Claude Desktop的配置文件中添加:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["-m", "mysql_mcp_server"],
"env": {
"MYSQL_MCP_HOST": "localhost",
"MYSQL_MCP_PORT": "3306",
"MYSQL_MCP_USER": "root",
"MYSQL_MCP_PASSWORD": "your_password",
"MYSQL_MCP_DATABASE": "your_database",
"MYSQL_MCP_READ_ONLY": "true"
}
}
}
}Cursor配置
在Cursor的MCP设置中添加:
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["-m", "mysql_mcp_server"],
"env": {
"MYSQL_MCP_HOST": "localhost",
"MYSQL_MCP_PORT": "3306",
"MYSQL_MCP_USER": "root",
"MYSQL_MCP_PASSWORD": "your_password",
"MYSQL_MCP_DATABASE": "your_database"
}
}
}
}🛠️ 工具列表
工具 | 说明 | 安全级别 |
| 列出所有可访问的数据库 | 🟢 只读 |
| 列出指定数据库的所有表 | 🟢 只读 |
| 获取表的详细结构(列、索引、建表语句) | 🟢 只读 |
| 执行SQL查询(仅SELECT/SHOW/DESCRIBE) | 🟢 只读 |
| 获取表的样本数据 | 🟢 只读 |
| 获取表的统计信息(行数、大小等) | 🟢 只读 |
| 获取SQL执行计划 | 🟢 只读 |
| 执行写操作(INSERT/UPDATE/DELETE) | 🔴 需关闭只读 |
⚙️ 环境变量
变量 | 默认值 | 说明 |
| localhost | MySQL主机地址 |
| 3306 | MySQL端口 |
| root | MySQL用户名 |
| (空) | MySQL密码 |
| (空) | 默认数据库 |
| true | 只读模式 |
| 100 | 查询结果最大行数 |
| 30 | 查询超时(秒) |
| (空=全部) | 允许访问的数据库列表 |
| (空=无) | 禁止访问的表列表 |
🔒 安全说明
默认只读 — 服务器启动后默认为只读模式,只能执行SELECT等查询
写操作需显式开启 — 设置
MYSQL_MCP_READ_ONLY=false才能使用execute_write访问控制 — 可通过
ALLOWED_DATABASES限制可访问的数据库表级屏蔽 — 可通过
BLOCKED_TABLES屏蔽敏感表(支持通配符)结果限制 — 默认最多返回100行,防止意外返回大量数据
超时保护 — 查询默认30秒超时,防止长时间运行的查询
📝 使用示例
在Claude中对话
你: 帮我看看数据库里有哪些表
Claude: [调用 list_databases → list_tables] 你的数据库中有以下表...
你: users表的结构是什么?
Claude: [调用 describe_table] users表有以下字段...
你: 帮我查一下最近注册的10个用户
Claude: [调用 query] SELECT * FROM users ORDER BY created_at DESC LIMIT 10
你: 这个查询为什么这么慢?
Claude: [调用 explain_query] 让我看看执行计划...🏗️ 开发
# 克隆仓库
git clone https://github.com/your-username/mysql-mcp-server.git
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest tests/📄 License
MIT License
This server cannot be installed
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 Servers
- Flicense-qualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.Last updated
- Alicense-qualityDmaintenanceEnables AI assistants to safely query MySQL databases with read-only access by default, supporting table listing, structure inspection, and SQL queries with optional write operation control.Last updated33MIT
- Alicense-quality-maintenanceEnables AI assistants to securely interact with MySQL databases through tools for query execution, schema inspection, and transaction management. It features built-in safety controls like row limits and query validation to ensure safe and standardized database access.Last updated946
- AlicenseBqualityCmaintenanceEnables AI assistants to securely interact with MariaDB and MySQL databases using granular per-connection read/write permissions and transaction support. It allows users to manage multiple database connections, explore schemas, and execute controlled SQL queries through a standardized interface.Last updated6365MIT
Related MCP Connectors
Runtime permission, approval, and audit layer for AI agent tool execution.
Read-only bank access for your AI agent. Connects Claude, ChatGPT, Cursor, Gemini, Codex.
Provide real-time data querying and visualization by integrating Tako with your agents. Generate o…
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/lm203688/mysql-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server