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
254 stars

The MySQL MCP Server Pro is a powerful tool that provides database operations, anomaly analysis capabilities, and extensibility features through the Model Context Protocol. It offers multiple connection methods and robust permission controls for secure database interaction.

Installation

To install and configure the MySQL MCP Server Pro:

pip install mysql_mcp_server_pro

Create a .env file with your database configuration:

# 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

Running the Server

You can start the server in different modes:

SSE Mode

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

Streamable HTTP Mode (Default)

mysql_mcp_server_pro --envfile /path/to/.env

With OAuth Authentication

mysql_mcp_server_pro --oauth true

Client Configuration

Using with uvx

This method can be used directly with MCP-supported clients without downloading the source code:

{
	"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 Configuration

Add this to your MCP client tools (such as cursor, cline, etc.):

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

Start the server:

# Download dependencies
uv sync

# Start
uv run -m mysql_mcp_server_pro.server

# Custom env file location
uv run -m mysql_mcp_server_pro.server --envfile /path/to/.env

# OAuth Authentication
uv run -m mysql_mcp_server_pro.server --oauth true

SSE Mode Configuration

Add this to your MCP client tools:

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

Start the server:

# Download dependencies
uv sync

# Start
uv run -m mysql_mcp_server_pro.server --mode sse

# Custom env file location
uv run -m mysql_mcp_server_pro.server --mode sse --envfile /path/to/.env

STDIO Mode Configuration

Add this to your MCP client tools:

{
  "mcpServers": {
      "operateMysql": {
        "isActive": true,
        "name": "operateMysql",
        "command": "uv",
        "args": [
          "--directory",
          "/Volumes/mysql_mcp_server_pro/src/mysql_mcp_server_pro",
          "run",
          "-m",
          "mysql_mcp_server_pro.server",
          "--mode",
          "stdio"
        ],
        "env": {
          "MYSQL_HOST": "localhost",
          "MYSQL_PORT": "3306",
          "MYSQL_USER": "root", 
          "MYSQL_PASSWORD": "123456",
          "MYSQL_DATABASE": "a_llm",
          "MYSQL_ROLE": "admin"
       }
    }
  }
} 

OAuth 2.0 Authentication

  1. Start the authentication service:
uv run -m mysql_mcp_server_pro.server --oauth true
  1. Visit the authentication service at http://localhost:3000/login. Default username and password are configured in the env file.

  2. 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: Executes SQL commands based on permission configuration
  • get_chinese_initials: Converts Chinese field names to pinyin initials
  • get_db_health_running: Analyzes MySQL health status
  • get_table_desc: Searches for table structures
  • get_table_index: Searches for table indexes
  • get_table_lock: Checks for row-level or table-level locks
  • get_table_name: Searches for table names based on comments
  • get_db_health_index_usage: Gets the index usage statistics
  • optimize_sql: Provides SQL performance optimization suggestions

Usage Examples

Creating a Table and Inserting Data

# 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

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

Analyzing Slow SQL

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

Analyzing SQL Deadlock Issues

update t_admin_rms_zzjg set sfyx = '0' where xh = '1' is stuck, please analyze the cause

Checking MySQL Health Status

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