How to Set Up a MySQL MCP Server for Claude, Cursor & Codex
Connect Claude, Cursor, Codex, or any AI agent to your MySQL database using MCP. Compare the best MySQL MCP servers and set one up in minutes.
MCP
This post was written by an engineer at QueryPlane. QueryPlane is an app builder for your database: bring your own postgres db and you can create interactive applications to share with other developers, coworkers or even your customers. If you’re interested in trying it out, get started here.
MCP (Model Context Protocol) lets AI tools like Claude Desktop, Claude Code, Cursor, and Codex connect directly to your MySQL database. Instead of copy-pasting schemas and query results into chat, the AI can inspect your tables, run queries, and analyze your data autonomously.
In this post, we’ll cover:
- What is MCP — How the protocol works
- Best MySQL MCP servers — Comparing dedicated and multi-database options
- Setup guides — Step-by-step for Claude Desktop and Claude Code
- Security considerations — Keeping your database safe
What is MCP?
The Model Context Protocol is an open standard created by Anthropic that lets AI applications connect to external data sources and tools. Think of it as a USB-C port for AI — a standardized way for any AI client to talk to any data source.
For databases, MCP servers expose tools like list_tables, describe_table, and execute_sql that AI agents can call. This means Claude or Codex can explore your schema, write queries based on your actual table structure, and validate results — all without you manually providing context.
Best MySQL MCP Servers
1. mcp-server-mysql
benborla/mcp-server-mysql (~1,570 stars) is the most popular dedicated MySQL MCP server.
Features:
- Schema inspection (list tables, describe columns)
- Read-only by default (write operations opt-in)
- SSH tunneling and SSL/TLS support
- Connection pooling and query caching
- Multi-database mode
Claude Desktop config:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@benborla29/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "password",
"MYSQL_DB": "mydb"
}
}
}
}
Claude Code setup:
MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASS=password MYSQL_DB=mydb \
claude mcp add --transport stdio mysql -- \
npx -y @benborla29/mcp-server-mysql
2. mysql_mcp_server
designcomputer/mysql_mcp_server (~1,230 stars) is a Python-based alternative focused on secure database interaction.
Features:
- Python-based (pip install)
- Secure connection handling
- Schema exploration and query execution
3. DBHub (Bytebase)
DBHub (~2,600 stars) is a multi-database MCP server that supports MySQL alongside PostgreSQL, SQL Server, MariaDB, and SQLite with a single install.
Features:
- Zero dependencies — runs via npx
- Token-efficient (only 2 MCP tools to maximize AI context window)
- Built-in web UI for testing
- Read-only mode
Claude Code setup:
claude mcp add --transport stdio dbhub -- \
npx @bytebase/dbhub@latest \
--transport stdio \
--dsn "mysql://user:pass@localhost:3306/mydb"
4. Google MCP Toolbox for Databases
googleapis/mcp-toolbox (~14,800 stars) is the most comprehensive multi-database MCP server. It supports MySQL alongside PostgreSQL, BigQuery, Snowflake, ClickHouse, MongoDB, and many more.
Features:
- Prebuilt generic tools (list_tables, execute_sql)
- Custom tools framework for domain-specific queries
- Connection pooling and IAM auth
- OpenTelemetry observability built in
5. MCP-Alchemy
mcp-alchemy (~400 stars) uses SQLAlchemy under the hood, so it works with any database SQLAlchemy supports — including MySQL.
See what QueryPlane can build for you
Connect to your database, write SQL with AI, and build shareable apps — all from your browser.
Which MySQL MCP Server Should You Use?
| Server | Stars | Dedicated MySQL | Multi-database | Read-only mode |
|---|---|---|---|---|
| mcp-server-mysql | ~1,600 | Yes | No | Yes (default) |
| mysql_mcp_server | ~1,230 | Yes | No | No |
| DBHub | ~2,600 | No | Yes | Yes |
| Google MCP Toolbox | ~14,800 | No | Yes | Configurable |
| MCP-Alchemy | ~400 | No | Yes | No |
For most developers, start with mcp-server-mysql — it’s the simplest dedicated option. If you work with multiple databases, use DBHub or Google MCP Toolbox.
Security Considerations
Connecting an AI agent to your MySQL database carries risk. Follow these practices:
- Use a read-only database user — create a dedicated user with SELECT-only permissions
- Connect to a replica — point MCP at a read replica, not your primary
- Limit schema access — restrict the user to specific databases
- Don’t expose credentials in configs — use environment variables for connection strings
- Enable the general query log — track what the AI runs
-- Create a read-only user for MCP
CREATE USER 'mcp_reader'@'%' IDENTIFIED BY 'secure_password';
GRANT SELECT ON mydb.* TO 'mcp_reader'@'%';
FLUSH PRIVILEGES;
Using MCP with QueryPlane
If you want the benefits of AI-powered database access without managing MCP servers, QueryPlane provides this out of the box. Connect your MySQL database and use AI to generate queries, explore schemas, and build dashboards — all from your browser with built-in access controls and team collaboration.
FAQ
What is a MySQL MCP server?
A MySQL MCP server is a process that implements the Model Context Protocol to let AI tools (Claude, Cursor, Codex, Windsurf) connect to your MySQL database. It exposes tools for listing tables, describing schemas, and running SQL queries.
How do I connect Claude to MySQL?
Install an MCP server like mcp-server-mysql via npx, then add it to your Claude Desktop config or use claude mcp add in Claude Code. The AI can then query your database directly.
Is it safe to connect AI to my MySQL database?
It can be safe with proper precautions: use a read-only database user, connect to a replica, limit schema access, and audit queries. Never give an MCP server write access to a production database without careful access controls.
Does MCP work with managed MySQL (RDS, Cloud SQL, PlanetScale)?
Yes. MCP servers connect via standard MySQL connection strings. Any managed provider that allows external connections (AWS RDS, Google Cloud SQL, Azure Database for MySQL, PlanetScale) works with MCP.
Wrapping up
MCP makes it easy to give AI agents direct access to your MySQL data. Whether you choose a dedicated server like mcp-server-mysql or a multi-database option like DBHub, start with a read-only setup and see how it fits your workflow.