# mcp-server-mysql — Read-Only MySQL MCP for Claude Code > mcp-server-mysql is an MCP server for Claude Code that connects to MySQL (optionally via SSH tunnels) so agents can inspect schemas and run read-only SQL. ## Install Merge the JSON below into your `.mcp.json`: ## Quick Use ```bash # Add the MCP server to Claude Code (read-only by default) claude mcp add mcp_server_mysql \ -e MYSQL_HOST="127.0.0.1" \ -e MYSQL_PORT="3306" \ -e MYSQL_USER="root" \ -e MYSQL_PASS="" \ -e MYSQL_DB="" \ -e ALLOW_INSERT_OPERATION="false" \ -e ALLOW_UPDATE_OPERATION="false" \ -e ALLOW_DELETE_OPERATION="false" \ -- npx @benborla29/mcp-server-mysql # Verify claude mcp list ``` ## Intro Connect Claude Code to a MySQL database with explicit read-only guards and optional SSH tunnel automation, so queries are auditable and repeatable. **Best for:** Database exploration, troubleshooting, and schema QA where you want an agent to run SQL without write access **Works with:** Claude Code (or any MCP client); MySQL; optional SSH tunnels for remote DBs **Setup time:** 5–10 minutes ### Key facts (verified) - README shows a Claude Code config with `ALLOW_*_OPERATION=false` toggles for read-only safety. - Supports SSH tunnel workflows and auto start/stop hooks (per README). - Uses `npx @benborla29/mcp-server-mysql` as the standard stdio entrypoint for Claude Code (per README). - GitHub: 1,638 stars · 206 forks; pushed 2026-03-10 (GitHub API verified). ## Main A safe pattern for “agent queries” is: 1. Keep the MCP server **read-only** (leave `ALLOW_INSERT_OPERATION`, `ALLOW_UPDATE_OPERATION`, `ALLOW_DELETE_OPERATION` set to `false`). 2. Ask the agent to **describe intent before executing** (e.g., “I will run a `SELECT ... LIMIT 50` to validate hypothesis X”). 3. Use the agent for **schema discovery** first (tables, columns, indexes) before any large query. 4. When connecting to a remote DB, use the README’s **SSH tunnel support** and keep credentials out of version control (prefer env prompts / local secret stores). If you later need writes (migrations, backfills), flip write flags only for a time-bounded session and keep a human in the loop. ### FAQ **Q: Is it read-only?** A: By default, yes. The README config shows write operations gated by `ALLOW_*_OPERATION` env flags. **Q: Can it connect to a remote DB?** A: Yes. The README highlights SSH tunnel support for remote MySQL. **Q: How do I verify it’s working in Claude Code?** A: Use `claude mcp list` and then try a small schema query (e.g., list tables) before larger SQL. ## Source & Thanks > Source: https://github.com/benborla/mcp-server-mysql > License: MIT > GitHub stars: 1,638 · forks: 206 --- ## 快速使用 ```bash # 添加到 Claude Code(默认只读) claude mcp add mcp_server_mysql \ -e MYSQL_HOST="127.0.0.1" \ -e MYSQL_PORT="3306" \ -e MYSQL_USER="root" \ -e MYSQL_PASS="<你的密码>" \ -e MYSQL_DB="<你的数据库>" \ -e ALLOW_INSERT_OPERATION="false" \ -e ALLOW_UPDATE_OPERATION="false" \ -e ALLOW_DELETE_OPERATION="false" \ -- npx @benborla29/mcp-server-mysql # 验证 claude mcp list ``` ## 简介 把 Claude Code 接到 MySQL:默认只读防护 + 可选 SSH 隧道自动管理,让查询可审计、可复现。 **最适合:** 让 Agent 参与查库/排障/验结构,但你希望它默认没有写权限的场景 **适配:** Claude Code(或任意 MCP 客户端);MySQL;可选 SSH 隧道连接远程数据库 **配置时间:** 5–10 分钟 ### 关键事实(已验证) - README 给出 Claude Code 配置示例:通过 `ALLOW_*_OPERATION=false` 开关实现默认只读。 - README 提到支持 SSH 隧道与自动 start/stop hook(隧道生命周期管理)。 - README 的 Claude Code 入口是 `npx @benborla29/mcp-server-mysql`(stdio)。 - GitHub:1,638 stars · 206 forks;最近更新 2026-03-10(GitHub API 验证)。 ## 正文 更安全的“Agent 查库”模式建议: 1. MCP server 保持 **只读**:`ALLOW_INSERT_OPERATION` / `ALLOW_UPDATE_OPERATION` / `ALLOW_DELETE_OPERATION` 全部保持 `false`。 2. 让 Agent **先说清楚意图再执行**(例如“我将执行 `SELECT ... LIMIT 50` 来验证假设 X”)。 3. 先做 **结构探索**(表/字段/索引),再做更重的查询。 4. 远程数据库场景,优先走 README 的 **SSH 隧道能力**,并避免把凭证写进仓库(用 env prompt / 本地密钥管理)。 需要写入(迁移/回填)时,尽量只在短时窗口打开写权限,并保持人工审核。 ### FAQ **默认是只读吗?** 答:是的。README 的配置示例用 `ALLOW_*_OPERATION` 环境变量开关来控制写操作,默认可保持关闭。 **能连远程数据库吗?** 答:可以。README 强调支持 SSH 隧道连接远程 MySQL。 **如何在 Claude Code 里验证?** 答:先用 `claude mcp list` 看 server 状态,再从小查询(如列出表)开始逐步确认。 ## 来源与感谢 > Source: https://github.com/benborla/mcp-server-mysql > License: MIT > GitHub stars: 1,638 · forks: 206 --- Source: https://tokrepo.com/en/workflows/mcp-server-mysql-read-only-mysql-mcp-for-claude-code Author: MCP Hub