MySQL MCP Server
Supports connecting to Google Cloud SQL instances via the Cloud SQL Proxy, enabling secure access to Cloud SQL databases.
Provides read-only access to MySQL databases, with tools to list tables, describe table schemas, and execute SQL queries.
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 Serverlist all tables in the 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
A Model Context Protocol (MCP) server for MySQL databases. Provides safe, read-only access to MySQL databases with automatic query sanitization, Google Cloud SQL Proxy support, and remote HTTP deployment options.
Features
Read-Only Access: All queries are sanitized to ensure only read operations are allowed
Google Cloud SQL Proxy: Built-in support for connecting to Cloud SQL instances
Remote HTTP Mode: Deploy as a remote service with API key authentication
Docker Support: Production-ready Docker images for easy deployment
Token Optimization: Results are automatically limited to minimize token usage
Related MCP server: mysql-mcp-server
Quick Start
Local Usage with Claude Code
Add to your project's .mcp.json:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@matpb/mysql-mcp-server"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Remote HTTP Server
Deploy as a remote service and connect from anywhere:
{
"mcpServers": {
"mysql": {
"type": "http",
"url": "https://your-server.example.com/mcp",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}Available Tools
Tool | Description |
| List all tables in the database |
| Get detailed schema information for a table |
| Execute any read-only SQL query |
Configuration
Environment Variables
Copy .env.example to .env and configure:
cp .env.example .envMySQL Connection
Variable | Default | Description |
|
| MySQL server host |
|
| MySQL server port |
|
| MySQL username |
| - | MySQL password |
| - | Database name |
|
| Connection pool size |
|
| Connection timeout (ms) |
Query Settings
Variable | Default | Description |
|
| Query timeout (ms) |
|
| Maximum rows returned |
HTTP Transport (Remote Mode)
Variable | Default | Description |
|
| Transport mode: |
|
| HTTP server port |
| - | Comma-separated API keys for authentication |
|
| CORS allowed origin |
Google Cloud SQL Proxy
Variable | Default | Description |
|
| Enable Cloud SQL Proxy |
| - | Instance connection name ( |
|
| Local proxy port |
| - | Path to service account JSON |
|
| Auto-download proxy binary |
|
| Startup timeout (ms) |
Docker Deployment
Project Structure
mysql-mcp-server/
├── docker/
│ ├── Dockerfile # Standard Docker image
│ ├── Dockerfile.digitalocean # Image with baked-in credentials
│ ├── docker-compose.yml # Docker Compose configuration
│ └── .env.example # Docker environment template
├── src/ # Source code
└── .env.example # Environment templateBuild and Run Locally
# Copy and configure environment
cp docker/.env.example .env
# Edit .env with your settings:
# - Set API_KEYS for authentication
# - Configure MySQL connection
# - (Optional) Configure Cloud SQL Proxy
# Build and start
cd docker
docker compose up -d
# View logs
docker compose logs -f
# Stop
docker compose downDeploy to Cloud Platforms
Step 1: Prepare Credentials (if using Cloud SQL)
# Create a service account
gcloud iam service-accounts create mysql-mcp-server \
--display-name="MySQL MCP Server"
# Grant Cloud SQL Client role
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
--member="serviceAccount:mysql-mcp-server@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/cloudsql.client"
# Generate key file
gcloud iam service-accounts keys create docker/service-account.json \
--iam-account=mysql-mcp-server@YOUR_PROJECT_ID.iam.gserviceaccount.comStep 2: Build for AMD64
Most cloud platforms run AMD64. Build with:
docker buildx build --platform linux/amd64 \
-f docker/Dockerfile.digitalocean \
-t your-registry.com/mysql-mcp-server:latest \
--push .Step 3: Configure Environment Variables
Set these in your cloud platform:
Variable | Value |
|
|
|
|
| Your secure API key |
| Database username |
| Database password (mark as secret) |
| Database name |
|
|
|
|
Step 4: Connect from Claude Code
{
"mcpServers": {
"mysql": {
"type": "http",
"url": "https://your-deployment-url.com/mcp",
"headers": {
"X-API-Key": "your-secure-api-key"
}
}
}
}Test Your Deployment
curl -X POST https://your-server.com/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "X-API-Key: your-api-key" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}'Google Cloud SQL Proxy
Local Development
For local development, use Application Default Credentials:
# Install gcloud CLI
brew install google-cloud-sdk # macOS
# Authenticate
gcloud auth application-default loginThen configure your .mcp.json:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@matpb/mysql-mcp-server"],
"env": {
"CLOUD_SQL_PROXY_ENABLED": "true",
"CLOUD_SQL_INSTANCE": "your-project:region:instance",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Production with Service Account
{
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json",
"CLOUD_SQL_PROXY_ENABLED": "true",
"CLOUD_SQL_INSTANCE": "your-project:region:instance"
}
}Security
Query Sanitization
The server automatically rejects:
Data modification:
INSERT,UPDATE,DELETE,DROP,CREATE,ALTER,TRUNCATETransactions:
BEGIN,COMMIT,ROLLBACKFile operations:
INTO OUTFILE,INTO DUMPFILELock operations:
LOCK TABLES,FOR UPDATE
Allowed Operations
SELECTqueriesSHOWcommandsDESCRIBE/DESCcommandsEXPLAINqueriesWITHclauses (CTEs)
Best Practices
Use HTTPS in production (via reverse proxy or cloud platform)
Generate strong API keys:
openssl rand -hex 32Restrict CORS to specific domains
Rotate API keys regularly
Never commit
.envfiles or service account credentials
Development
# Install dependencies
npm install
# Build
npm run build
# Run in stdio mode (local)
npm start
# Run in HTTP mode
MCP_TRANSPORT=http-stream API_KEYS=test-key npm start
# Watch mode
npm run watchTroubleshooting
Cloud SQL Proxy Errors
"could not find default credentials"
Run
gcloud auth application-default loginOr set
GOOGLE_APPLICATION_CREDENTIALSto your service account file
"Access denied for user"
Verify MySQL username/password
Check that your service account has
Cloud SQL Clientrole
HTTP Transport Errors
"Session not found"
The MCP client must send proper session headers
Test with the MCP Inspector:
npx @modelcontextprotocol/inspector
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Read-only SaaS business intelligence from GA4, Stripe, and Google Search Console.
Generate, fix, explain and run read-only SQL on PostgreSQL, MySQL and SQL Server
Related MCP Servers
AlicenseNot gradedqualityBmaintenanceEnables secure read-only access to MySQL databases with automatic database inference from project context. Provides safe querying capabilities with built-in security features like parameterized queries, whitelisting, and rate limiting.1MIT- AlicenseAqualityDmaintenanceProvides read-only MySQL query execution, database/table browsing, and table structure inspection with SQL safety validation.57 npmMIT
- AlicenseNot gradedqualityCmaintenanceProvides secure, read-only access to a single MySQL database for schema inspection and querying.72 npm5MIT
- AlicenseNot gradedqualityDmaintenanceA secure, read-only MySQL database proxy using MCP protocol, enabling SQL queries and table inspections via HTTP.10 npm1MIT