zhineng.dev Tools

简体中文 | [English]

MCP MySQL Server

A MySQL server with DDL operations, permission control, and operation logging support.

Version History

v3.0.0 (Latest Version)

v2.0.1

v2.0.0

Features

Installation

Global Installation (Recommended)

npm install -g @liangshanli/mcp-server-mysql

Local Installation

npm install @liangshanli/mcp-server-mysql

Install from Source

git clone https://github.com/liliangshan/mcp-server-mysql.git
cd mcp-server-mysql
npm install

Configuration

Set environment variables:

export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export READONLY=false
export ALLOW_DDL=true
export ALLOW_DROP=false
export ALLOW_DELETE=false

Quick Start

1. Install the Package

npm install -g @liangshanli/mcp-server-mysql

2. Configure Environment Variables

export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export READONLY=false
export ALLOW_DDL=false
export ALLOW_DROP=false
export ALLOW_DELETE=false

3. Run the Server

mcp-server-mysql

Editor Integration

Cursor Editor Configuration

Create .cursor/mcp.json file in project root:

Single Instance Configuration
{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-mysql"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database",
        "READONLY": "false",
        "ALLOW_DDL": "false",
        "ALLOW_DROP": "false",
        "ALLOW_DELETE": "false"
      }
    }
  }
}
Multi-instance Configuration
{
  "mcpServers": {
    "mysql-prod": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-mysql"],
      "env": {
        "MYSQL_HOST": "prod.example.com",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "prod_user",
        "MYSQL_PASSWORD": "prod_password",
        "MYSQL_DATABASE": "prod_db",
        "READONLY": "true",
        "TOOL_PREFIX": "prod",
        "PROJECT_NAME": "Production Environment"
      }
    },
    "mysql-test": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-mysql"],
      "env": {
        "MYSQL_HOST": "test.example.com",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "test_user",
        "MYSQL_PASSWORD": "test_password",
        "MYSQL_DATABASE": "test_db",
        "TOOL_PREFIX": "test",
        "PROJECT_NAME": "Test Environment"
      }
    }
  }
}

VS Code Configuration - .vscode/mcp.json Format

1. Install MCP extension for VS Code
2. Create .vscode/mcp.json file:

Single Instance Configuration
{
  "servers": {
    "mysql": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-mysql"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}
Multi-instance Configuration
{
  "servers": {
    "mysql-prod": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-mysql"],
      "env": {
        "MYSQL_HOST": "prod.example.com",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "prod_user",
        "MYSQL_PASSWORD": "prod_password",
        "MYSQL_DATABASE": "prod_db",
        "READONLY": "true",
        "TOOL_PREFIX": "prod",
        "PROJECT_NAME": "Production Environment"
      }
    },
    "mysql-test": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-mysql"],
      "env": {
        "MYSQL_HOST": "test.example.com",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "test_user",
        "MYSQL_PASSWORD": "test_password",
        "MYSQL_DATABASE": "test_db",
        "TOOL_PREFIX": "test",
        "PROJECT_NAME": "Test Environment"
      }
    }
  }
}