An mcp that can connect to mysql
Configuration
View docs{
"mcpServers": {
"404-error-notfound-mcp_mysql": {
"url": "http://localhost:9000/sse",
"headers": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_ROLE": "admin",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password"
}
}
}
}You deploy a MySQL Model Context Protocol (MCP) server to analyze, monitor, and manage MySQL databases with AI-assisted guidance. It supports both direct STDIO integration and HTTP Server-Sent Events, enabling cross-database queries, health checks, and smart analysis across your MySQL environment.
Launch the MCP server and connect your MCP client to perform cross-database queries, health analyses, and AI-assisted operations. You can choose between STDIO mode for direct integration with tools like Cursor and Cline, or SSE mode for a web-based workflow. Use the included tools to list databases, inspect table structures, analyze health and index usage, and convert Chinese field names to pinyin initials. Ensure your client is configured with the correct environment variables and permissions before executing commands.
Prerequisites before you begin: install Python 3.10 or newer, ensure the UV package manager is available, and have a MySQL server accessible with proper credentials.
# Prerequisites
python3 --version
# Ensure Python 3.10+ is installed
# Install the UV package manager (one of the supported methods shown below)
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Linux/macOS
curl -LsSf https://astral.sh/uv/install.sh | shClone the MCP project and synchronize dependencies, then prepare the environment file with your MySQL connection details.
# Windows (PowerShell)
git clone <repository-url>
cd mcp_mysql
uv sync
```
```bash
# Linux/macOS
git clone <repository-url>
cd mcp_mysql
uv syncCreate a .env file at the project root with your MySQL connection details. You can provide a specific database or leave it empty for cross-database access. The role determines your permission level for MCP operations.
# 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, adminYou have two modes to run the server: SSE (HTTP-based) for web integrations and STDIO for direct, local usage. Start the server in SSE mode to expose an endpoint at a default port for MCP clients.
# SSE mode (Web-based)
uv run server.py
```
```json
{
"mcpServers": {
"mysql": {
"name": "mysql",
"description": "MySQL database operations",
"isActive": true,
"baseUrl": "http://localhost:9000/sse"
}
}
}For STDIO mode, you run the server locally and connect via a standard input/output channel. This is useful for tightly coupled tooling that communicates through a process boundary.
# STDIO mode
uv run server.py --stdio
```
```json
{
"mcpServers": {
"mysql": {
"name": "mysql",
"command": "uv",
"args": [
"run", "server.py", "--stdio"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_ROLE": "admin"
}
}
}
}The server enforces role-based access control with three permission levels: readonly, writer, and admin. These roles determine which SQL operations you can perform, including data manipulation and DDL actions.
Ensure the MySQL port is reachable from the server host, verify environment variables in your .env file, and check the server logs for any connection or authentication errors. If you encounter policy or firewall issues, adjust the local firewall rules to allow MySQL traffic and the MCP server port.
Leverage cross-database access to run queries across multiple databases without switching connections, and use the available tools to analyze health, performance, and lock status across your MySQL environment.
You can extend the server with custom tools. Define a new tool class, implement your logic, and register it so it appears in your MCP client workflow.
Cross-database operations let you join data across databases without changing connections. You can query table descriptions across databases and run health analytics to spot bottlenecks.
Execute SQL statements with role-based permission control across connected databases.
List all available databases excluding system databases to support cross-database workflows.
Retrieve table structures across databases, supporting the database.table format.
Retrieve table indexes with cross-database support.
Find tables by comments and descriptions to aid discovery.
Analyze MySQL health including connections, transactions, and locks.
Analyze index usage and provide performance recommendations.
Detect row-level and table-level locks to identify contention.
Convert Chinese field names to pinyin initials for easier handling.