mysql_mcp
Provides tools for interacting with MySQL databases, including listing instances, executing queries with security features like write guards, schema allowlists, rate limiting, and query timeouts, all managed via SSH tunnels to multiple MySQL Docker containers.
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_mcplist tables in app_db"
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
A production-grade MCP server that connects Claude to multiple MySQL Docker containers on a VPS. All connections are defined in a single JSON file. Each connection can optionally manage its own SSH tunnel — no autossh, no systemd services, no external tooling required.
How it works
Claude Desktop
│
└── mysql_mcp (one process)
├── "app" → SSH tunnel → VPS:3306 (app_db) writes ON
├── "analytics" → SSH tunnel → VPS:3307 (analytics_db) read-only
└── "legacy" → SSH tunnel → VPS:3308 (legacy_db) read-onlyOn startup the server:
Reads
connections.json(or another configured path — see below)Spawns one SSH tunnel per connection that has
ssh_hostBlocks until each tunnel's local port accepts TCP connections
Opens a MySQL connection pool through each tunnel
Starts a background watcher per tunnel that auto-reconnects if SSH dies
Related MCP server: Claude MCP Server Ecosystem
Security features
Feature | Details |
SQL injection defence | Blocks |
Forbidden statements |
|
Write guard per connection |
|
Schema allowlist |
|
TLS per connection | Configure TLS independently per container |
Rate limiting | Per-connection sliding 60s window (default 120 req/min) |
Query timeout | Cancels runaway queries server-side (default 30s) |
Row cap | Hard ceiling on rows returned per query (default 500) |
Identifier sanitisation | DB/table names validated against |
No secrets in code | All credentials live in |
Config validation | Missing/invalid fields caught at startup with clear error messages |
SSH tunnel manager
The built-in tunnel manager replaces autossh. It:
Spawns
ssh -N -L ...as a subprocess withExitOnForwardFailure=yesandServerAliveIntervalBlocks startup until the local port actually accepts a TCP connection (15s timeout)
Runs a background watcher task per tunnel
Reconnects with exponential backoff when SSH dies — delay doubles per failure, capped at
ssh_max_delayResets the MySQL connection pool after a successful reconnect so stale connections don't linger
Returns a clear
"tunnel is reconnecting — please try again shortly"error during reconnectsTerminates cleanly on shutdown (SIGTERM → 3s grace → SIGKILL)
Quick start
1. Docker Compose on your VPS
Bind each container to a different port on 127.0.0.1 — never 0.0.0.0:
# docker-compose.yml
services:
mysql-app:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${APP_ROOT_PW}
MYSQL_DATABASE: app_db
ports:
- "127.0.0.1:3306:3306"
volumes:
- app_data:/var/lib/mysql
mysql-analytics:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${ANALYTICS_ROOT_PW}
MYSQL_DATABASE: analytics_db
ports:
- "127.0.0.1:3307:3306"
volumes:
- analytics_data:/var/lib/mysql
mysql-legacy:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${LEGACY_ROOT_PW}
ports:
- "127.0.0.1:3308:3306"
volumes:
- legacy_data:/var/lib/mysql
volumes:
app_data:
analytics_data:
legacy_data:2. Create least-privilege MySQL users
-- mysql-app (writes allowed)
CREATE USER 'mcp_app'@'%' IDENTIFIED BY 'strong_password_1';
GRANT SELECT, INSERT, UPDATE, DELETE, SHOW DATABASES, SHOW VIEW
ON app_db.* TO 'mcp_app'@'%';
-- mysql-analytics (read-only)
CREATE USER 'mcp_analytics'@'%' IDENTIFIED BY 'strong_password_2';
GRANT SELECT, SHOW DATABASES, SHOW VIEW ON analytics_db.* TO 'mcp_analytics'@'%';
-- mysql-legacy (read-only, two schemas)
CREATE USER 'mcp_legacy'@'%' IDENTIFIED BY 'strong_password_3';
GRANT SELECT, SHOW DATABASES, SHOW VIEW ON legacy_db.* TO 'mcp_legacy'@'%';
GRANT SELECT, SHOW DATABASES, SHOW VIEW ON archive_db.* TO 'mcp_legacy'@'%';
FLUSH PRIVILEGES;3. Set up SSH key auth on the VPS
# Generate a dedicated key for the MCP server (no passphrase — it runs unattended)
ssh-keygen -t ed25519 -f ~/.ssh/mcp_vps -C "mysql-mcp" -N ""
# Copy the public key to the VPS
ssh-copy-id -i ~/.ssh/mcp_vps.pub ubuntu@your-vps.example.com
# Verify it works without a password prompt
ssh -i ~/.ssh/mcp_vps -o BatchMode=yes ubuntu@your-vps.example.com echo ok4. Install the MCP server locally
cd mysql-mcp
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt5. Create your connections file
cp connections.example.json connections.json
$EDITOR connections.json # fill in your VPS hostname, passwords, key pathThe file is plain JSON with // and # line comments supported:
// connections.json
[
{
"name": "app",
"label": "App Database",
"host": "127.0.0.1",
"port": 13306,
"user": "mcp_app",
"password": "strong_password_1",
"database": "app_db",
"allow_writes": true,
"allowed_dbs": ["app_db"],
// SSH tunnel — managed automatically by the MCP server
"ssh_host": "your-vps.example.com",
"ssh_user": "ubuntu",
"ssh_key": "/home/you/.ssh/mcp_vps",
"ssh_remote_port": 3306,
"ssh_local_port": 13306
},
{
"name": "analytics",
"label": "Analytics Database",
"host": "127.0.0.1",
"port": 13307,
"user": "mcp_analytics",
"password": "strong_password_2",
"database": "analytics_db",
"allowed_dbs": ["analytics_db"],
"max_rows": 1000,
"ssh_host": "your-vps.example.com",
"ssh_user": "ubuntu",
"ssh_key": "/home/you/.ssh/mcp_vps",
"ssh_remote_port": 3307,
"ssh_local_port": 13307
},
{
"name": "legacy",
"label": "Legacy Database",
"host": "127.0.0.1",
"port": 13308,
"user": "mcp_legacy",
"password": "strong_password_3",
"allowed_dbs": ["legacy_db", "archive_db"],
"ssh_host": "your-vps.example.com",
"ssh_user": "ubuntu",
"ssh_key": "/home/you/.ssh/mcp_vps",
"ssh_remote_port": 3308,
"ssh_local_port": 13308
}
]6. Configure Claude Desktop
~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
%APPDATA%\Claude\claude_desktop_config.json (Windows)
{
"mcpServers": {
"mysql": {
"command": "/absolute/path/to/mysql-mcp/.venv/bin/python",
"args": ["/absolute/path/to/mysql-mcp/server.py"],
"env": {
"MYSQL_CONFIG": "/absolute/path/to/mysql-mcp/connections.json"
}
}
}
}Restart Claude Desktop after saving.
Where the config file is loaded from
The server searches these locations in order and uses the first one found:
Priority | Source |
1 | Path in |
2 |
|
3 |
|
4 |
|
5 | Inline JSON in |
All connection fields
MySQL fields
Field | Type | Required | Default | Description |
| string | ✓ | — | Unique identifier ( |
| string | ✓ | — | MySQL host (usually |
| string | ✓ | — | MySQL username |
| string | ✓ | — | MySQL password |
| int |
| MySQL port | |
| string |
| Human-readable display name | |
| string |
| Default schema | |
| bool |
| Enforce TLS on the MySQL connection | |
| string |
| Path to CA certificate (recommended with TLS) | |
| string |
| Path to client cert (mutual TLS) | |
| string |
| Path to client key (mutual TLS) | |
| bool |
| Allow | |
|
|
| Schema whitelist — empty means all visible schemas | |
| int |
| Max rows returned per query | |
| int |
| Query timeout in seconds | |
| int |
| Max queries per minute |
SSH tunnel fields
All optional. Omit the ssh_* fields entirely if MySQL is already reachable without a tunnel.
Field | Type | Required | Default | Description |
| string | ✓ to enable | — | VPS hostname or IP |
| int |
| SSH port on the VPS | |
| string | system default | SSH login username | |
| string | — | Path to SSH private key (strongly preferred over password) | |
| string | — | SSH password | |
| string |
| MySQL host as seen from the VPS | |
| int | same as | MySQL port as seen from the VPS | |
| int | ✓ if | — | Local port the tunnel binds to |
| int |
|
| |
| int |
| Initial reconnect wait in seconds | |
| int |
| Max reconnect wait — exponential backoff ceiling |
Available tools
Tool | Description |
| List all connections with config and live tunnel state — call this first |
| Execute SQL on a named connection |
| List schemas visible on a connection |
| List tables and views in a schema |
| Full schema: columns, indexes, |
|
|
| Version, uptime, connection counts, TLS status, tunnel state |
What the logs look like
Normal startup:
[INFO] Loading connections from: /home/you/mysql-mcp/connections.json
[INFO] Connection 'app' (App Database): mysql=127.0.0.1:13306 db=app_db writes=True tunnel=your-vps.example.com:13306
[INFO] Starting 3 SSH tunnel(s)…
[INFO] SSH tunnel 'app' ready on 127.0.0.1:13306 (connect #1)
[INFO] SSH tunnel 'analytics' ready on 127.0.0.1:13307 (connect #1)
[INFO] SSH tunnel 'legacy' ready on 127.0.0.1:13308 (connect #1)
[INFO] MySQL pool ready for 'app' (127.0.0.1:13306)
[INFO] MySQL pool ready for 'analytics' (127.0.0.1:13307)
[INFO] MySQL pool ready for 'legacy' (127.0.0.1:13308)
[INFO] All connections ready ✓Tunnel drops and reconnects:
[WARNING] SSH tunnel 'app' died (exit 255). Reconnecting in 5s…
[WARNING] SSH stderr for 'app': Connection to your-vps.example.com closed.
[INFO] SSH tunnel 'app' ready on 127.0.0.1:13306 (connect #2)Query during reconnect:
{ "error": "SSH tunnel for 'app' is reconnecting — please try again shortly." }Adding a new container later
Add one more object to connections.json and restart the MCP server. No code changes:
{
"name": "warehouse",
"label": "Data Warehouse",
"host": "127.0.0.1",
"port": 13309,
"user": "mcp_warehouse",
"password": "strong_password_4",
"database": "warehouse_db",
"allowed_dbs": ["warehouse_db"],
"ssh_host": "your-vps.example.com",
"ssh_user": "ubuntu",
"ssh_key": "/home/you/.ssh/mcp_vps",
"ssh_remote_port": 3309,
"ssh_local_port": 13309
}Production checklist
connections.jsonis in.gitignoreand never committedEach MySQL user has only the minimum required privileges
allow_writes: falsefor every read-only connectionallowed_dbsset for every connection to restrict schema accessAll Docker containers bound to
127.0.0.1on the VPS — not0.0.0.0A dedicated SSH key with no passphrase is used (
ssh-keygen -t ed25519)All MySQL passwords are strong and randomly generated
max_rowsandquery_timeoutare tuned per connection's workloadssh_keepalive: 30(default) detects dead connections within ~90s
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.
Latest Blog Posts
- 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/yogaaltariz/mysql-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server