MySQL MCP Server
An MCP server for interacting with MySQL databases.
This server supports executing read-only queries (query) and write queries that are ultimately rolled back (test_execute).
Setup
Environment Variables
Add the following environment variables to ~/.mcp/.env
:
Note:
host.docker.internal
is a special DNS name for accessing host machine services from Docker containers. Use this setting when connecting to a MySQL server running on your host machine. If connecting to a different MySQL server, change to the appropriate hostname.
mcp.json Configuration
Usage
Starting the Server
Note: If you're using OrbStack,
host.docker.internal
is automatically supported, so the--add-host
option can be omitted. While Docker Desktop also typically supports this automatically, adding the--add-host
option is recommended for better reliability.
Available Commands
1. Execute Read-only Query
Response:
2. Test Query Execution
Response:
3. List Tables
Response:
4. Describe Table
Response:
Implementation Details
- Implemented in TypeScript
- Uses mysql2 package
- Runs as a Docker container
- Accepts JSON commands through standard input
- Returns JSON responses through standard output
- Uses
host.docker.internal
to connect to host MySQL (compatible with both OrbStack and Docker Desktop)
Security Considerations
- Uses environment variables for sensitive information management
- SQL injection prevention is the implementer's responsibility
- Proper network configuration required for production use
- Appropriate firewall settings needed when connecting to host machine services
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
可以通过 JSON 命令与 MySQL 数据库交互,支持只读查询、写入查询的测试执行以及通过 Docker 检索表信息。
Related Resources
Related MCP Servers
- -securityFlicense-qualityFacilitates interaction with a local MySQL database via a RESTful API, supporting database queries and real-time updates with integration for Cursor MCP services.Last updated -4
- AsecurityAlicenseAqualityConnect and interact with MySQL databases seamlessly. Execute SQL queries, manage database connections, and retrieve data directly through AI assistants. Enhance your AI capabilities with structured access to your MySQL data.Last updated -9017MIT License
- -securityFlicense-qualityEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.Last updated -
- -securityFlicense-qualityAn executable MySQL server implementation that facilitates database connections and operations with built-in stability features and configuration options.Last updated -