MySQL MCP Server
Provides comprehensive MySQL database operations including cross-database queries, schema discovery, performance monitoring, health analysis, lock detection, and AI-assisted database management with role-based access control.
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 MCP Servershow me the top 5 largest tables by row count across all databases"
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 comprehensive Model Context Protocol (MCP) server for MySQL database operations with advanced features for database analysis, health monitoring, and AI-assisted database management.
đ Features
MySQL MCP Server goes beyond basic CRUD operations, providing powerful database analysis capabilities and an extensible framework for custom tools.
đ Transport Modes
STDIO Mode: Direct integration with MCP clients like Cursor, Cline
SSE Mode: HTTP-based Server-Sent Events for web applications
đī¸ Database Operations
Cross-Database Access: Connect once, access all databases without switching connections
Multi-Statement Execution: Execute multiple SQL statements separated by ";"
Smart Table Discovery: Find tables by comments and descriptions
SQL Execution Plan Analysis: Performance optimization insights
đĄī¸ Security & Permissions
Role-Based Access Control: Three permission levels (readonly, writer, admin)
SQL Comment Support: Handles SQL statements with
--and/* */comments
đ Advanced Analysis
Health Monitoring: Connection, transaction, and lock status analysis
Performance Insights: Index usage analysis and optimization recommendations
Lock Detection: Row-level and table-level lock monitoring
Chinese Text Processing: Pinyin conversion for Chinese field names
đ¤ AI Integration
Prompt Templates: Pre-built AI prompts for database analysis and querying
Context-Aware Assistance: Intelligent database operation guidance
đ Permission Levels
Role | Permissions | Use Case |
readonly |
| Read-only access for reporting and analysis |
writer | readonly + | Application development and data manipulation |
admin | Full database administration | Complete database management including DDL, user management, backup/recovery |
đ ī¸ Available Tools
Database Operations
Tool | Description |
| Execute SQL statements with role-based permission control |
| List all available databases (excluding system databases) |
Schema Discovery
Tool | Description |
| Get table structures across databases (supports |
| Retrieve table indexes with cross-database support |
| Find tables by comments and descriptions |
Performance & Health
Tool | Description |
| Analyze MySQL health (connections, transactions, locks) |
| Index usage analysis with performance recommendations |
| Detect row-level and table-level locks |
Utilities
Tool | Description |
| Convert Chinese field names to pinyin initials |
đ¤ AI Prompt Templates
Prompt Template | Purpose |
| Comprehensive MySQL issue analysis and troubleshooting |
| Intelligent table data querying with AI assistance |
đ Quick Start
Prerequisites
Python 3.10+
UV package manager
MySQL server
Installation
đĻ Installing UV Package Manager
Windows:
# Using PowerShell (Recommended)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Or using pip
pip install uv
# Or using Chocolatey
choco install uv
# Or using Scoop
scoop install uvLinux/macOS:
# Using curl
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or using pip
pip install uvđŊ Project Setup
Clone and install dependencies:
Windows (PowerShell):
git clone <repository-url> cd mcp_mysql uv syncLinux/macOS:
git clone <repository-url> cd mcp_mysql uv syncConfigure database connection:
Create a
.envfile in the project root directory:Windows (PowerShell):
# Create .env file using PowerShell @" # MySQL Database Configuration MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=your_username MYSQL_PASSWORD=your_password # MYSQL_DATABASE=specific_db # Optional: leave empty for cross-database access MYSQL_ROLE=admin # Options: readonly, writer, admin "@ | Out-File -FilePath ".env" -Encoding utf8Or manually create
.envfile with content:# MySQL Database Configuration MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=your_username MYSQL_PASSWORD=your_password # MYSQL_DATABASE=specific_db # Optional: leave empty for cross-database access MYSQL_ROLE=admin # Options: readonly, writer, adminFor remote MySQL server (example):
MYSQL_HOST=192.168.1.100 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=your_secure_password MYSQL_ROLE=admin
Running the Server
SSE Mode (Web-based)
Windows (PowerShell):
# Start SSE server on http://localhost:9000
uv run server.pyLinux/macOS:
# Start SSE server on http://localhost:9000
uv run server.pyMCP Client Configuration (SSE):
{
"mcpServers": {
"mysql": {
"name": "mysql",
"description": "MySQL database operations",
"isActive": true,
"baseUrl": "http://localhost:9000/sse"
}
}
}STDIO Mode (Direct integration)
Windows (PowerShell):
# Start STDIO server
uv run server.py --stdioLinux/macOS:
# Start STDIO server
uv run server.py --stdioMCP Client Configuration (STDIO):
Windows:
{
"mcpServers": {
"mysql": {
"name": "mysql",
"command": "uv",
"args": [
"--directory", "C:\\path\\to\\mcp_mysql\\src",
"run", "server.py", "--stdio"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_ROLE": "admin"
}
}
}
}Linux/macOS:
{
"mcpServers": {
"mysql": {
"name": "mysql",
"command": "uv",
"args": [
"--directory", "/path/to/mcp_mysql/src",
"run", "server.py", "--stdio"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_ROLE": "admin"
}
}
}
}đ ī¸ Windows-Specific Configuration Notes
Common Issues and Solutions
PowerShell Execution Policy: If you encounter execution policy errors, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserPath Separators:
Use double backslashes
\\or forward slashes/in JSON configurationExample:
"C:\\Users\\YourName\\mcp_mysql"or"C:/Users/YourName/mcp_mysql"
Environment Variables in Windows:
# Set environment variables temporarily (current session)
$env:MYSQL_HOST = "localhost"
$env:MYSQL_USER = "your_username"
$env:MYSQL_PASSWORD = "your_password"
# Run the server with environment variables
uv run server.py --stdioWindows Firewall: Ensure MySQL port (default 3306) is allowed through Windows Firewall if connecting to remote MySQL server.
đ§ Extending with Custom Tools
Create a new tool class:
# src/handles/my_custom_tool.py from .base import BaseHandler from mcp.types import Tool, TextContent class MyCustomTool(BaseHandler): name = "my_custom_tool" description = "Description of what this tool does" def get_tool_description(self) -> Tool: # Define tool schema pass async def run_tool(self, arguments: dict) -> list[TextContent]: # Implement tool logic passRegister the tool:
# src/handles/__init__.py from .my_custom_tool import MyCustomTool __all__ = [..., "MyCustomTool"]
đĄ Usage Examples
Cross-Database Operations
List all databases:
Use get_databases toolCross-database queries:
SELECT u.name, o.total
FROM users_db.users u
JOIN orders_db.orders o ON u.id = o.user_id;Table structure analysis:
get_table_desc: "users_db.users,orders_db.orders"AI-Assisted Operations
Performance Analysis:
Analyze this slow query and suggest optimizations:
SELECT * FROM large_table lt
LEFT JOIN another_table at ON lt.id = at.foreign_id
WHERE lt.created_date > '2024-01-01'Health Monitoring:
Check MySQL health status and identify any performance issuesSmart Table Discovery:
Find all tables related to user management across all databasesDeadlock Analysis:
Analyze why this UPDATE statement is stuck:
UPDATE users SET status = 'active' WHERE id = 123đ Documentation
Development Guide - For developers working with this codebase
API Reference - Detailed tool and prompt documentation
đ¤ Contributing
Fork the repository
Create a feature branch
Add your custom tools or improvements
Submit a pull request
đ License
This project is open source. Please check the license file for details.
Star this repository if you find it helpful! â
This server cannot be installed
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
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/404-error-notfound/mcp_mysql'
If you have feedback or need assistance with the MCP directory API, please join our Discord server