Navigation
mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync - MCP Implementation

mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync

Mirror your MySQL databases flawlessly – MySQL-MCP Server ensures zero-downtime replication, real-time sync, and bulletproof disaster recovery. Your data’s safest, smartest guardian." )

Developer Tools
4.8(134 reviews)
201 saves
93 comments

Users create an average of 51 projects per month with this tool

About mysql-mcp-server

What is mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync?

mysql-mcp-server is a specialized server application enabling AI models to interact with MySQL 8.0 databases through the Model Context Protocol (MCP). It ensures seamless operations with zero-downtime replication for continuous data availability and real-time sync for instant updates. Built using Python and FastMCP, it connects AI workflows with database operations via a modular executor framework.

How to use mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync?

Deployment Options

  • Docker: Configure environment variables and run docker run -d --name mcp-mysql ...
  • Docker Compose: Use predefined setup with docker-compose up -d
  • Python: Install dependencies and execute python main.py run

Tool Configuration

Create or modify executors in mysql_mcp_server/executors, register them in __init__.py, and ensure Cursor Pro compatibility (requires version 0.46+).

mysql-mcp-server Features

Key Features of mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync

  • Real-Time Database Interaction: Execute SQL queries (SELECT/INSERT), schema analysis, and visualization recommendations without service interruptions
  • Modular Tool System: 8 core executors (e.g., create_table, explain, invoke_viz_pro) with extensible architecture
  • Security-first Design: Environment variable management, SSH connection support (planned), and query safety controls
  • Scalable Architecture: FastMCP interface layer, business logic handlers, and database manager with singleton connection pooling

Use cases of mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync

  • Data Analysis Automation: Generate dynamic reports with chart recommendations using invoke_viz_pro
  • Real-Time Dashboard Sync: Keep AI-driven dashboards updated via automatic MySQL query execution
  • Multi-Environment Replication: Maintain sync between development/staging/production databases without service breaks
  • AI-Driven Schema Management: Use insight_starter to validate database structures before report generation

mysql-mcp-server FAQ

FAQ from mysql-mcp-server: Zero-Downtime Replication & Real-Time Sync

What MySQL versions are supported?

MySQL 8.0 is required for all features. Compatibility with earlier versions isn't guaranteed due to protocol differences.

How do I secure database connections?

Use environment variables for credentials and enable SSL/TLS in production. Planned SSH tunnel support will enhance remote access security.

Can I disable specific tools?

Coming soon - future releases will add tool-level enable/disable switches to control functionality and reduce API costs.

What's the difference between executors and tools?

Executors are physical Python modules in /executors, while tools are their registered API representations exposed to AI models via MCP.

Content

mysql-mcp-server

한국어 README.md

0. Execution

Running with Docker

Change the database connection information as needed.

docker run -d --name mcp-mysql \
  -e MYSQL_HOST=localhost \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=mcpTest1234!!! \
  -e MYSQL_DATABASE=mcp_test \
  -e MCP_PORT=8081 \
  -p 3306:3306 mineru/mcp-mysql:1.0.0

Running with Docker Compose

This will proceed with a pre-configured setup.

docker-compose up -d

Running directly with Python

pip install -r requirements.txt
python mysql_mcp_server/main.py run

Cursor Configuration

MCP functionality is available from Cursor version 0.46 and above.

Additionally, the MCP feature is only accessible to Cursor Pro account users.

Cursor Setting

Tool Addition Tips

  • Adding a Tool

    • execute functions implement the actual logic execution (Service Layer).
    • The @tool decorator helps register the tool with MCP (Controller Layer).
  • Explanation

    • Each file under mysql_mcp_server/executors represents a single tool.
    • If a new tool is added, it must be imported in mysql_mcp_server/executors/__init__.py and included in the __all__ array.
    • This ensures the module is automatically registered in the TOOLS_DEFINITION variable.

    flowchart LR;
    A[AI Model] -->|Request tool list| B[MCP Server]
    B -->|Return available tools| A

    A -->|Request specific tool execution| B
    B -->|Call the corresponding executor| C[Executors]
    
    subgraph Executors
        C1[execute_create_table] -->|Create table| D
        C2[execute_desc_table] -->|View table schema| D
        C3[execute_explain] -->|Query execution plan| D
        C4[execute_insert_query] -->|Execute INSERT query| D
        C5[execute_insight_starter] -->|Checking the schema for building reports| D
        C6[execute_invoke_viz_pro] -->|Visualization chart recommendations| D
        C7[execute_select_query] -->|Execute SELECT query| D
        C8[execute_show_tables] -->|Retrieve table list| D
    end
    
    D[DatabaseManager] -->|Connect to MySQL| E[MySQL 8.0]
    
    E -->|Return results| D
    D -->|Send results| C
    C -->|Return results| B
    B -->|Return execution results| A
    

🚧 Development Roadmap 🚧

  • ⚙️ Parameter Options

    • 🔧 Enable/Disable Switch for Each Tool: Provide a function to reduce Input Context costs 💰
    • 🔒 Query Security Level Setting: Offer optional control over functions that could damage asset value, such as DROP, DELETE, UPDATE 🚫
  • ✨ Features

    • 📊 Data Analysis Report Generation: Provide a report generation function optimized for the model to appropriately select various charts based on user requests 📈
      • 📝 Reporting capabilities for prescribed forms
      • 🖌️ Diversify report templates
    • 🗄️ Extended Text2SQL Support
    • 🌐 SSH Connection Support: Enable secure remote access via SSH for advanced operations 🔑
    • 📥 File Extraction Function
      • 📄 CSV
      • 📑 JSON
      • 📉 Excel

1. Overview

MCP MySQL Server is a server application for MySQL database operations based on MCP (Model Context Protocol). This server provides tools that allow AI models to interact with the MySQL database.

2. System Configuration

2.1 Key Components

  • MCP Server : A FastMCP server that communicates with AI models
  • MySQL Database : Manages and stores data
  • Tools : Executors that perform database operations

2.2 Tech Stack

  • Language : Python
  • Database : MySQL 8.0
  • Key Libraries :
    • mcp: Implements Model Context Protocol for AI communication
    • PyMySQL: Connects to MySQL and executes queries
    • pandas: Processes and analyzes data
    • python-dotenv: Manages environment variables
    • fire: Implements command-line interfaces

2.3 Deployment Environment

  • Containerized deployment via Docker and Docker Compose
  • Ports: 8081 (MCP Server), 3306 (MySQL)

3. Directory Structure

MCPBoilerPlate/
├── mysql_mcp_server/           # Main application directory
│   ├── executors/              # Database operation executors
│   │   ├── create_table.py     # Tool for creating tables
│   │   ├── desc_table.py       # Tool for viewing table schema
│   │   ├── explain.py          # Tool for query execution plans
│   │   ├── insert_query.py     # Tool for INSERT query execution
│   │   ├── insight_starter.py  # Schema verification tools for write reports
│   │   ├── invoke_viz_pro.py   # Tool for Visualization chart recommendation
│   │   ├── select_query.py     # Tool for SELECT query execution
│   │   └── show_tables.py      # Tool for retrieving table lists
│   ├── helper/                 # Utility modules
│   │   ├── db_conn_helper.py   # Manages database connections
│   │   ├── logger_helper.py    # Logging utilities
│   │   └── tool_decorator.py   # Tool decorator
│   └── main.py                 # Application entry point
├── docker-compose.yml          # Docker Compose configuration
├── Dockerfile                  # Docker image build settings
├── requirements.txt            # Dependency package list
└── .env.example                # Example environment variables file

4. Architecture Design

4.1 Layered Structure

  1. Interface Layer : MCP Server (FastMCP)
  2. Business Logic Layer : Handlers and Executors
  3. Data Access Layer : Database connection and query execution

4.2 Key Classes and Modules

  • MySQLMCPServer : Main server class that initializes and runs the MCP server
  • DatabaseManager : Singleton pattern-based database connection manager
  • Executors : Collection of tools for database operations
    • execute_create_table: Creates tables
    • execute_desc_table: Checks table schema
    • execute_explain: Provides query execution plans
    • execute_insert_query: Executes INSETR queries
    • execute_select_query: Executes SELECT queries
    • execute_show_tables: Retrieves table lists

4.3 Communication Flow

  1. AI model requests a list of available tools from the MCP server.
  2. The server returns the available tools list.
  3. The AI model requests the execution of a specific tool.
  4. The server calls the corresponding executor to perform the database operation.
  5. The execution results are returned to the AI model.

5. Scalability and Maintenance

  • Adding Tools : Implement new tools in the executors directory and register them in __init__.py.
  • Environment Configuration : Manage environment variables via the .env file.
  • Logging : Ensure consistent logging using logger_helper.

6. Deployment and Execution

6.1 Local Execution

# Setup environment
cp .env.example .env
# Modify .env file as needed

# Install dependencies
pip install -r requirements.txt

# Run the server
python mysql_mcp_server/main.py run

6.2 Docker Deployment

# Start database using Docker Compose
docker-compose up -d db
# Build and run mysql-mcp-server with Docker Compose (including rebuilds)
docker-compose up -d --build mysql-mcp-server

7. Security Considerations

  • Manage database credentials via environment variables.
  • Use strong passwords in production environments.
  • Consider implementing SSL/TLS encryption for database connections when necessary.

Related MCP Servers & Clients