MySQL Database Manager MCP server

Provides direct access to MySQL databases with advanced features like multiple SQL execution, table metadata querying, execution plan analysis, and Chinese field to pinyin conversion through a configurable Python-based server.
Back to servers
Setup instructions
Provider
wenb1n-dev
Release date
Apr 10, 2025
Language
Python
Stats
220 stars

MySQL MCP Server Pro is a powerful tool that enables you to interact with MySQL databases through the Model Context Protocol, providing not only basic CRUD operations but also advanced database analysis capabilities. It supports various authentication methods and transfer modes to fit your specific needs.

Installation

To install the MySQL MCP Server Pro, use pip:

pip install mysql_mcp_server_pro

Configuration

Create a .env file with your MySQL database connection details:

# MySQL Database Configuration
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
# Optional, default is 'readonly'. Available values: readonly, writer, admin
MYSQL_ROLE=readonly

The permission roles control what SQL operations are allowed:

  • readonly: Can only execute SELECT, SHOW, DESCRIBE, and EXPLAIN statements
  • writer: Can also execute INSERT, UPDATE, and DELETE statements
  • admin: Has full access including CREATE, ALTER, DROP, and TRUNCATE statements

Running the Server

You can run the server in different modes:

Streamable HTTP Mode (Default)

mysql_mcp_server_pro --envfile /path/to/.env

SSE Mode

mysql_mcp_server_pro --mode sse --envfile /path/to/.env

STDIO Mode

This mode is typically used when configuring the server within an MCP client.

Client Configuration

Using uvx (Recommended for MCP Clients)

For MCP-supported clients, add this configuration:

{
    "mcpServers": {
        "mysql": {
            "command": "uvx",
            "args": [
                "--from",
                "mysql_mcp_server_pro",
                "mysql_mcp_server_pro",
                "--mode",
                "stdio"
            ],
            "env": {
                "MYSQL_HOST": "192.168.x.xxx",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASSWORD": "root",
                "MYSQL_DATABASE": "a_llm",
                "MYSQL_ROLE": "admin"
            }
        }
    }
}

Streamable HTTP Mode

Configure your MCP client with:

{
  "mcpServers": {
    "mysql_mcp_server_pro": {
      "name": "mysql_mcp_server_pro",
      "type": "streamableHttp",
      "description": "",
      "isActive": true,
      "url": "http://localhost:3000/mcp/"
    }
  }
}

Start the server:

uv run -m mysql_mcp_server_pro.server

SSE Mode

Configure your MCP client with:

{
  "mcpServers": {
    "mysql_mcp_server_pro": {
      "name": "mysql_mcp_server_pro",
      "description": "",
      "isActive": true,
      "url": "http://localhost:9000/sse"
    }
  }
}

Start the server:

uv run -m mysql_mcp_server_pro.server --mode sse

OAuth2.0 Authentication

To enable OAuth2.0 authentication:

uv run -m mysql_mcp_server_pro.server --oauth true

Visit http://localhost:3000/login to get your authentication token.

Add the token to your client configuration:

{
  "mcpServers": {
    "mysql_mcp_server_pro": {
      "name": "mysql_mcp_server_pro",
      "type": "streamableHttp",
      "description": "",
      "isActive": true,
      "url": "http://localhost:3000/mcp/",
      "headers": {
        "authorization": "bearer TOKEN_VALUE"
      }
    }
  }
}

Available Tools

The server provides several powerful tools:

  • execute_sql: Execute SQL commands based on your permission level
  • get_chinese_initials: Convert Chinese field names to pinyin initials
  • get_db_health_running: Analyze MySQL health status
  • get_table_desc: Search for table structures
  • get_table_index: Search for table indexes
  • get_table_lock: Check for locks in the MySQL server
  • get_table_name: Search for table names based on comments
  • get_db_health_index_usage: Analyze index usage statistics

Usage Examples

Creating a Table

Example prompt:

# Task
   Create an organizational structure table with the following structure: department name, department number, parent department, is valid.
# Requirements
 - Table name: department
 - Common fields need indexes
 - Each field needs comments, table needs comment
 - Generate 5 real data records after creation

Querying Data Based on Table Comments

Example prompt:

Search for data with Department name 'Executive Office' in Department organizational structure table

Analyzing Slow SQL

Example prompt:

select * from t_jcsjzx_hjkq_cd_xsz_sk xsz
left join t_jcsjzx_hjkq_jcd jcd on jcd.cddm = xsz.cddm 
Based on current index situation, review execution plan and provide optimization suggestions in markdown format, including table index status, execution details, and optimization recommendations

Checking MySQL Health

Example prompt:

Check the current health status of MySQL

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mysql_mcp_server_pro" '{"command":"uvx","args":["--from","mysql_mcp_server_pro","mysql_mcp_server_pro","--mode","stdio"],"env":{"MYSQL_HOST":"localhost","MYSQL_PORT":"3306","MYSQL_USER":"your_username","MYSQL_PASSWORD":"your_password","MYSQL_DATABASE":"your_database","MYSQL_ROLE":"readonly"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mysql_mcp_server_pro": {
            "command": "uvx",
            "args": [
                "--from",
                "mysql_mcp_server_pro",
                "mysql_mcp_server_pro",
                "--mode",
                "stdio"
            ],
            "env": {
                "MYSQL_HOST": "localhost",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "your_username",
                "MYSQL_PASSWORD": "your_password",
                "MYSQL_DATABASE": "your_database",
                "MYSQL_ROLE": "readonly"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mysql_mcp_server_pro": {
            "command": "uvx",
            "args": [
                "--from",
                "mysql_mcp_server_pro",
                "mysql_mcp_server_pro",
                "--mode",
                "stdio"
            ],
            "env": {
                "MYSQL_HOST": "localhost",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "your_username",
                "MYSQL_PASSWORD": "your_password",
                "MYSQL_DATABASE": "your_database",
                "MYSQL_ROLE": "readonly"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later