The MySQL MCP Server allows interaction with MySQL databases via JSON commands in a Docker container. You can:
Execute read-only SQL queries (
query)Test SQL write queries with automatic rollback (
test_execute)List all tables in the database (
list_tables)Describe the structure of a specific table (
describe_table)
Runs as a containerized service with special configurations for host connectivity, allowing MySQL database access from Docker environments with proper networking setup.
Uses environment variables stored in .env files for configuration management, particularly for sensitive database connection credentials.
Enables interaction with MySQL databases through read-only queries, schema exploration, and safe testing of write operations (with rollback). Provides tools for executing queries, listing tables, and describing table structures.
Implemented in TypeScript, providing type-safe database interactions with MySQL.
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.internalis 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
Related MCP server: MySql MCP Server
Usage
Starting the Server
Note: If you're using OrbStack,
host.docker.internalis automatically supported, so the--add-hostoption can be omitted. While Docker Desktop also typically supports this automatically, adding the--add-hostoption 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.internalto 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