MySQL MCP Server
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.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MySQL MCP Server list all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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:
MYSQL_HOST=host.docker.internal # Hostname to access host services from Docker container
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_passwordNote:
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
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--add-host=host.docker.internal:host-gateway",
"--env-file",
"/Users/username/.mcp/.env",
"ghcr.io/xiangma9712/mcp/mysql"
]
}
}
}Related MCP server: MCP MySQL Server
Usage
Starting the Server
docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysqlNote: 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
{
"type": "query",
"payload": {
"sql": "SELECT * FROM your_table"
}
}Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "example"
}
]
}2. Test Query Execution
{
"type": "test_execute",
"payload": {
"sql": "UPDATE your_table SET name = 'updated' WHERE id = 1"
}
}Response:
{
"success": true,
"data": "The UPDATE SQL query can be executed."
}3. List Tables
{
"type": "list_tables"
}Response:
{
"success": true,
"data": ["table1", "table2", "table3"]
}4. Describe Table
{
"type": "describe_table",
"payload": {
"table": "your_table"
}
}Response:
{
"success": true,
"data": [
{
"Field": "id",
"Type": "int(11)",
"Null": "NO",
"Key": "PRI",
"Default": null,
"Extra": ""
},
{
"Field": "name",
"Type": "varchar(255)",
"Null": "YES",
"Key": "",
"Default": null,
"Extra": ""
}
]
}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
Available Tools
4 toolsdescribe_tableC
Retrieves column information for a table.
Inputs: tableName (required).
list_tablesB
Retrieves a list of tables in the database.
queryB
Executes a read-only SQL query.
Inputs: sql (required).
test_executeB
Checks if an SQL query can be executed and rolls back afterward.
Inputs: sql (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool has a clearly distinct purpose: describe_table for column metadata, list_tables for table enumeration, query for read-only SQL execution, and test_execute for query validation with rollback. There is no overlap in functionality, making tool selection straightforward for an agent.
The naming follows a consistent verb_noun pattern (describe_table, list_tables, query, test_execute), with 'query' as a minor deviation as it lacks a noun suffix. Overall, the pattern is predictable and readable, though not perfectly uniform.
With 4 tools, the count is reasonable for a database server, covering essential operations like listing tables, describing schema, querying, and testing queries. It is slightly lean but well-scoped, lacking only advanced features like write operations or transaction management.
The toolset covers basic read and validation operations but has notable gaps: there are no tools for data manipulation (e.g., insert, update, delete), schema modification (e.g., create_table), or transaction control. This limits the server to read-only and diagnostic tasks, which may cause agent failures for write workflows.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted MySQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Query, explore, and manage your databases through natural conversation.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.-
- AlicenseNot gradedqualityDmaintenanceEnables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.81 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI models to interact with MySQL databases through standardized operations including querying, executing commands, listing tables, and describing table structures with secure prepared statement support.290 npmMIT
- AlicenseAqualityDmaintenanceEnables querying local MySQL databases and managing Docker containers (listing, logs) through natural language via the Model Context Protocol.471 npmISC