Get the FREE Ultimate OpenClaw Setup Guide →

mysql

A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio he426100-mysql-mcp-server docker run -i --rm mysql-mcp-server --host 127.0.0.1 \
  --env DB_HOST="Database host" \
  --env DB_PORT="Database port (default 3306 if not specified)" \
  --env DB_DATABASE="Database name" \
  --env DB_PASSWORD="Database password" \
  --env DB_USERNAME="Database username"

How to use

This MCP server provides a controlled interface to a MySQL database, enabling an AI assistant to discover available tables, read data from tables, and execute SQL queries with built-in error handling. It exposes resources as table-like entities that can be inspected and queried safely, with access governed by the configured environment variables. You can ask the assistant to list tables, retrieve sample rows from a table, or run parameterized queries while the server enforces permissions and logs operations for auditing.

To interact with the server, deploy it in your environment (locally or in a container) and ensure your application or agent has the required DB credentials configured via environment variables. Use natural language prompts to request available resources (tables), read data from a specific table, or execute SQL statements. The MCP server will translate requests into secure, constrained database operations and return results or error messages accordingly.

How to install

Prerequisites:

  • Docker or PHP environment (depending on deployment method)
  • Access to a MySQL database with appropriate credentials
  • Git installed on your machine

Option A — Docker (recommended for isolation):

  1. Build the Docker image from the repository (if you have the Dockerfile): docker build -t mysql-mcp-server .
  2. Run the MCP server container with your database credentials injected (example): docker run -i --rm
    -e DB_HOST=your-db-host
    -e DB_PORT=3306
    -e DB_USERNAME=your_username
    -e DB_PASSWORD=your_password
    -e DB_DATABASE=your_database
    mysql-mcp-server --host 127.0.0.1

Option B — PHP (local development):

  1. Clone the repository: git clone https://github.com/he426100/mysql-mcp-server
  2. Navigate to the project: cd mysql-mcp-server
  3. Install PHP dependencies (Composer): composer install
  4. Create an environment file or export variables for the database connection: export DB_HOST=localhost export DB_PORT=3306 export DB_USERNAME=your_username export DB_PASSWORD=your_password export DB_DATABASE=your_database
  5. Run the server: php bin/console

Prerequisites recap:

  • Git
  • PHP with Composer or Docker (for container deployment)
  • Access credentials to a MySQL database
  • Network connectivity between the MCP server and the MySQL database

Additional notes

Security tips:

  • Never commit database credentials; use environment variables or secret management.
  • Use a MySQL user with least privileges necessary for the intended queries.
  • Consider enabling query whitelisting or parameterized requests in production.
  • Enable and monitor logging of all database operations for audit purposes.

Configuration tips:

  • Ensure DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD, and DB_DATABASE are correctly set before starting the server.
  • When running in Docker, pass credentials via -e flags or a secure environment file.
  • If hosting behind a firewall, restrict access to the MCP server interface accordingly.

Related MCP Servers

Sponsor this space

Reach thousands of developers