mysql
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases
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):
- Build the Docker image from the repository (if you have the Dockerfile): docker build -t mysql-mcp-server .
- 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):
- Clone the repository: git clone https://github.com/he426100/mysql-mcp-server
- Navigate to the project: cd mysql-mcp-server
- Install PHP dependencies (Composer): composer install
- 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
- 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
drift
Codebase intelligence for AI. Detects patterns & conventions + remembers decisions across sessions. MCP server for any IDE. Offline CLI.
laravel
A Laravel package for implementing secure Model Context Protocol servers using Streamable HTTP and SSE transport, providing real-time communication and a scalable tool system for enterprise environments.
php
基于 PHP 实现的 MCP (Model Control Protocol) 服务器框架,通过注解优雅地定义 MCP 服务,支持 Tool、Prompt、Resource 三种处理器,支持Stdio、Sse 两种 transport。
mcp-profiler-bundle
The Symfony MCP Profiler Bundle mimics the WebProfiler Bundle. It bridges the gap between Profiler data and your favorite MCP-enabled AI-powered IDE.
elementor
Comprehensive Elementor MCP Server plugin.
mcp
Model Context Protocol for Hyperf