Get the FREE Ultimate OpenClaw Setup Guide →

mysql

MySQL MCP Server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio adamosk-mysql-mcp-server node C:/path/to/mysql-mcp-server/mcp-mysql-lite.js

How to use

This MCP server provides secure, multi-database access to MySQL databases through the Model Context Protocol. It supports multiple databases, security levels that restrict what SQL commands can be executed, and lazy loading of connection pools so resources are used only when needed. The server exposes tools such as query_database, describe_table, and list_databases to let you explore schema information, run compliant queries, and inspect pool status. Resources from the default database are exposed as MCP resources with URIs like mysql://database_name/table/table_name, which can be browsed directly in the VS Code MCP exploration UI. To operate safely, you must explicitly select a target database before executing commands, and the security level determines which SQL statements are allowed. Hot reload updates configurations from the .env file without restarting the server, while lazy loading ensures pools are created on demand for each database.

How to install

Prerequisites:

  • Node.js and npm installed on your system
  • Access to a console with Git

Steps:

  1. Clone the repository and install dependencies
git clone <your-repository-url>
cd mysql-mcp-server
npm install
  1. Configure the multi-database setup Copy the example configuration and customize it:
cp .env.example .env

Edit the .env file to define your databases and security settings, for example:

# Multi-Database Configuration (JSON Array)
MYSQL_DATABASES='[
  {
    "name": "primary_db",
    "host": "localhost",
    "user": "your_username",
    "password": "your_password",
    "database": "your_database"
  },
  {
    "name": "analytics_db", 
    "host": "analytics.example.com",
    "user": "analytics_user",
    "password": "analytics_password",
    "database": "analytics"
  }
]'

# Security Configuration
# Options: (default), extended, all, or custom comma-separated list
# MYSQL_ALLOWED_COMMANDS=extended

# Connection Pool Settings
MYSQL_CONNECTION_LIMIT=4
MYSQL_WAIT_FOR_CONNECTIONS=true

# Server Metadata
MCP_SERVER_NAME=mysql-mcp-server
MCP_SERVER_VERSION=1.0.0
  1. Start the server
npm start
  1. Optional: Add to VS Code MCP Configuration
{
  "mcp": {
    "mcpServers": {
      "mysql-mcp-server": {
        "command": "node",
        "args": ["C:/path/to/mysql-mcp-server/mcp-mysql-lite.js"],
        "env": {}
      }
    }
  }
}

Note: Adjust the file paths and environment variables to match your environment.

Additional notes

Tips and notes:

  • Ensure each database entry in MYSQL_DATABASES has a unique name and valid host, user, and credentials.
  • The security level defined by MYSQL_ALLOWED_COMMANDS governs which SQL statements are permitted; use the default for read-only exploration and raise privileges in trusted environments only.
  • When you update .env, hot reload will apply credential changes, new databases, and host/port adjustments on the next connection; some changes may require a VS Code restart to update tool schemas.
  • The server enforces explicit database selection; always specify the target database for operations to avoid accidental changes.
  • Use list_databases to verify pool status and see which pools are active; lazy loading helps keep startup time fast and resource usage efficient.

Related MCP Servers

Sponsor this space

Reach thousands of developers