Get the FREE Ultimate OpenClaw Setup Guide →

mysql-query

MySQL Query MCP server for AI assistants - execute read-only MySQL queries

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio devakone-mysql-query-mcp-server npx mysql-query-mcp-server@latest \
  --env DEBUG="false" \
  --env LOCAL_DB_HOST="localhost" \
  --env LOCAL_DB_NAME="your_database" \
  --env LOCAL_DB_PASS="<YOUR_LOCAL_DB_PASSWORD>" \
  --env LOCAL_DB_PORT="3306" \
  --env LOCAL_DB_USER="root" \
  --env MCP_MYSQL_SSL="true" \
  --env STAGING_DB_HOST="staging.example.com" \
  --env STAGING_DB_NAME="your_database" \
  --env STAGING_DB_PASS="<STAGING_PASSWORD>" \
  --env STAGING_DB_PORT="3306" \
  --env STAGING_DB_USER="<STAGING_USER>" \
  --env PRODUCTION_DB_HOST="prod.example.com" \
  --env PRODUCTION_DB_NAME="your_database" \
  --env PRODUCTION_DB_PASS="<PRODUCTION_PASSWORD>" \
  --env PRODUCTION_DB_PORT="3306" \
  --env PRODUCTION_DB_USER="<PRODUCTION_USER>" \
  --env DEVELOPMENT_DB_HOST="dev.example.com" \
  --env DEVELOPMENT_DB_NAME="your_database" \
  --env DEVELOPMENT_DB_PASS="<DEV_PASSWORD>" \
  --env DEVELOPMENT_DB_PORT="3306" \
  --env DEVELOPMENT_DB_USER="<DEV_USER>" \
  --env MCP_MYSQL_REJECT_UNAUTHORIZED="false"

How to use

This MCP server exposes read-only access to MySQL databases via the MCP protocol. It supports three tools: query, info, and environments. The query tool lets you run safe, read-only SQL statements (SELECT, SHOW, DESCRIBE) against a selected environment. The info tool returns metadata about a database, such as server version, status, and variables. The environments tool lists all configured environments (local, development, staging, production) so your AI assistant can switch contexts easily. Configure your AI client to point at the MCP server using the appropriate environment variables; for example, specify LOCAL_ for the local environment and DEVELOPMENT_/STAGING_/PRODUCTION_ for the others. SSL and timeouts are supported to help keep connections secure and responsive.

How to install

Prerequisites:

  • Node.js (>= 14) and npm installed
  • Access to npm (for npx or global installation)

Option A: Run without installing globally (recommended for simplicity)

  1. Ensure Node.js and npm are installed
  2. Run the MCP server via npx (no global install required):
npx mysql-query-mcp-server@latest

This will start the server with defaults and listen for MCP configuration from your client.

Option B: Install globally for easier repeated use

  1. Install globally:
npm install -g mysql-query-mcp-server
  1. Run the server:
mysql-query-mcp-server

If you run into port or host binding issues, check environment configuration or pass appropriate environment variables as shown in the example configuration.

Additional notes

Tips and caveats:

  • The server enforces read-only queries (SELECT, SHOW, DESCRIBE). Attempts at write operations will be rejected.
  • Each environment connects to its own pool; ensure credentials and hostnames are correct for the target environment.
  • If using production credentials, consider secure secret management and avoid embedding plain passwords in configuration files.
  • Enable MCP_MYSQL_SSL if your environments require SSL; set MCP_MYSQL_REJECT_UNAUTHORIZED to false only in trusted networks.
  • Use the environments tool to verify which databases you can access and to verify available environments in your MCP config.

Related MCP Servers

Sponsor this space

Reach thousands of developers