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
Provider
wenb1n-dev
Release date
Apr 10, 2025
Language
Python
Stats
31 stars

This server provides a MySQL interface for executing SQL queries and performing database analysis. It offers a range of features beyond basic CRUD operations, including database health monitoring, anomaly analysis, and custom tool extensions.

Installation

Prerequisites

  • Python with uv package manager
  • Access to a MySQL database

Setup Instructions

  1. Clone the repository or download the source code
  2. Configure your MySQL database connection by setting environment variables

SSE Mode Setup

Create or modify your .env file with your MySQL connection details:

# MySQL Database Configuration
MYSQL_HOST=192.168.xxx.xxx
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=a_llm
MYSQL_ROLE=readonly  # Optional values: readonly, writer, admin

Install dependencies and start the server:

# Download dependencies
uv sync

# Start the server
uv run server.py

Then configure your MCP client (like Cursor or Cline) with the following JSON:

{
  "mcpServers": {
    "operateMysql": {
      "name": "operateMysql",
      "description": "",
      "isActive": true,
      "baseUrl": "http://localhost:9000/sse"
    }
  }
}

STDIO Mode Setup

Configure your MCP client with the following JSON, adjusting the directory path to match your setup:

{
  "mcpServers": {
    "operateMysql": {
      "isActive": true,
      "name": "operateMysql",
      "command": "uv",
      "args": [
        "--directory",
        "G:\\python\\mysql_mcp\\src",  # Replace with your project path
        "run",
        "server.py",
        "--stdio"
      ],
      "env": {
        "MYSQL_HOST": "192.168.xxx.xxx",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "root",
        "MYSQL_DATABASE": "a_llm",
        "MYSQL_ROLE": "readonly"
      }
    }
  }
}

Usage

The server provides several tools that can be invoked via your MCP client:

Available Tools

  • execute_sql: Execute SQL queries with permission-based controls
  • get_chinese_initials: Convert Chinese field names to pinyin initials
  • get_db_health_running: Analyze MySQL server health status
  • get_table_desc: Retrieve table structures from the database
  • get_table_index: Search for table indexes
  • get_table_lock: Check for row-level or table-level locks
  • get_table_name: Search for tables based on comments/descriptions
  • get_db_health_index_usage: Analyze index usage and identify issues

Permissions

The server supports three permission roles:

  • readonly: Can execute SELECT, SHOW, DESCRIBE, EXPLAIN
  • writer: Can also execute INSERT, UPDATE, DELETE
  • admin: Full access including CREATE, ALTER, DROP, TRUNCATE

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: t_admin_rms_zzjg
 - Field requirements: string type uses 'varchar(255)', integer type uses 'int'
 - Table header needs to include primary key field, serial number XH varchar(255)
 - Table must include these fixed fields at the end: creator-CJR varchar(50), creation time-CJSJ datetime
 - Generate 5 real data records after creation

Querying Data Based on Table Comments

Query Zhang San's data from the user information 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

Checking MySQL Health Status

Check the current health status of MySQL

Analyzing Deadlock Issues

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

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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