home / mcp / mysql mcp server

MySQL MCP Server

MySQL MCP Server

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "adamosk-mysql-mcp-server": {
      "command": "node",
      "args": [
        "C:/path/to/mysql-mcp-server/mcp-mysql-lite.js"
      ],
      "env": {
        "MCP_SERVER_NAME": "mysql-mcp-server",
        "MYSQL_DATABASES": "[{\"name\":\"primary_db\",\"host\":\"localhost\",\"user\":\"dbuser\",\"password\":\"secret\",\"database\":\"db\"}]",
        "MCP_SERVER_VERSION": "1.0.0",
        "MYSQL_ALLOWED_COMMANDS": "extended",
        "MYSQL_CONNECTION_LIMIT": "4",
        "MYSQL_WAIT_FOR_CONNECTIONS": "true"
      }
    }
  }
}

You can run a MySQL MCP Server that securely exposes multiple MySQL databases to an MCP client. It supports lazy loading, hot reloading of configuration, and explicit database selection to prevent accidental operations, making it ideal for safe data exploration and controlled administration.

How to use

To access your configured databases, run the MCP server locally and connect to it from your MCP-enabled client (for example, your editor or IDE’s MCP integration). You will browse available databases, run read or write operations according to the security level you configure, and inspect complete table definitions directly from the client’s resource tree.

Key usage patterns you will perform include selecting a specific database for every operation, executing queries within your allowed command set, and describing table schemas to understand structure and constraints. You can view which pools are active and monitor connection status through the provided tooling.

How to install

# Prerequisites
- Node.js installed on your system
- npm available in your PATH

# 1. Clone and install
git clone <your-repository-url>
cd mysql-mcp-server
npm install

# 2. Configure multi-database setup
cp .env.example .env

# Edit .env with your database configurations
# 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

Additional configuration and usage notes

Security levels determine which SQL commands you can run. The default level is read-only for safe analysis, with options to allow schema changes or full administration through explicit settings in your environment file.

To enable your MCP client with the server, add a configuration entry pointing to the local MCP runtime. The following is an example for a VS Code MCP setup.

{
  "mcp": {
    "mcpServers": {
      "mysql-mcp-server": {
        "command": "node",
        "args": ["C:/path/to/mysql-mcp-server/mcp-mysql-lite.js"],
        "env": {}
      }
    }
  }
}

Operational notes

Hot reload updates to database configurations are picked up automatically, so you can adjust credentials, add new databases, or change host/port values without restarting the server. Existing connections stay active and will be refreshed as needed.

Lazy loading means connection pools are created only when a database is actually used, keeping resource usage efficient and startup fast. Use the status indicators provided by the server tooling to verify which pools are active.

Available tools

query_database

Execute SQL queries with security validation and explicit database selection. Returns query results with execution metadata.

describe_table

Get complete table structure using SHOW CREATE TABLE for comprehensive schema information, including columns, indexes, and constraints.

list_databases

Display all configured databases and their connection pool status.