Enables loading of environment variables from .env files for configuring database connections, supporting parameters like host, port, user, password, and database name.
Provides tools for querying, modifying, and exploring MySQL databases, including executing SQL queries, getting query execution plans, viewing database schemas, previewing table contents, and switching between databases.
Uses Pydantic models for database configuration validation and type safety when handling connection parameters and query results.
MySQL-MCP
A powerful MySQL database connector for Claude built with the Model Context Protocol (MCP)
MySQL-MCP gives Claude direct access to your MySQL databases through the Model Context Protocol. It provides a complete set of tools for querying, modifying, and exploring your databases with simple natural language instructions.
Features
Query execution: Run any SQL query against your database
Query explanation: Get detailed query execution plans
Schema exploration: View databases, tables, and column definitions
Data inspection: Preview table contents with sample rows
Safety first: Controls to prevent accidental data loss
Best practices: Built-in prompts to help Claude write optimal SQL
Full logging: Comprehensive logging of all operations
Installation
There are several ways to install MySQL-MCP:
Option 1: Install from Source with pip
Option 2: Install as a Development Package
Option 3: Install with FastMCP (for Claude integration)
First, install FastMCP:
Then install the MySQL-MCP package:
Quick Start
Environment Setup
Create a .env
file with your MySQL connection details:
Running with Claude
If you haven't already, install your MySQL MCP app in Claude:
In Claude, select the MySQL MCP tool from the tool selector
Now you can ask Claude to:
"Show me all databases available"
"What tables are in the customers database?"
"Query all orders placed in the last week"
"Show me the schema for the users table"
"Help me optimize this slow query: SELECT * FROM orders JOIN users ON user_id WHERE status = 'pending'"
Running Locally
You can also run the MCP server locally for development:
Advanced Usage
Connecting to Multiple Databases
You can create configurations for multiple databases and switch between them:
Transaction Support
For operations that need to be atomic:
Schema Analysis
Provide deeper insights into database structure:
Security Considerations
MySQL-MCP executes SQL directly against your database
Only provide access to databases that Claude should have access to
Consider using a read-only user for safety
Review all queries before execution when working with production data
Limit connection permissions based on the principle of least privilege
Troubleshooting
If you encounter issues:
Check your
.env
file for correct database credentialsVerify that MySQL server is running and accessible
Look at the log file (
mysql_mcp.log
) for detailed error informationMake sure all dependencies are installed:
pip install -r requirements.txt
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Built with FastMCP, the fast, Pythonic way to build Model Context Protocol servers.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A connector that gives Claude direct access to MySQL databases through the Model Context Protocol, enabling natural language querying, schema exploration, and database management.
Related MCP Servers
- -securityFlicense-qualityA natural language interface that allows Claude to execute SQL queries on your local MySQL databases, enabling database interaction using natural language.Last updated -2
- AsecurityAlicenseAqualityAn MCP server that enables MySQL database integration with Claude. You can execute SQL queries and manage database connections.Last updated -27MIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that enables Claude to access and interact with Oracle databases through natural language queries.Last updated -3MIT License
- -securityAlicense-qualityThis server enables Claude to directly interact with SQLite, SQL Server, PostgreSQL, and MySQL databases through the Model Context Protocol, allowing for query execution, table management, and data export capabilities.Last updated -MIT License