Skip to main content
Glama

MySQL MCP Server

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_password

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

{ "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" ] } } }

Usage

Starting the Server

docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysql

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
{ "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.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
Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

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.

Enables interaction with a MySQL database via JSON commands, supporting read-only queries, test execution of write queries, and table information retrieval through Docker.

  1. Setup
    1. Environment Variables
    2. mcp.json Configuration
  2. Usage
    1. Starting the Server
    2. Available Commands
  3. Implementation Details
    1. Security Considerations

      Related MCP Servers

      • A
        security
        F
        license
        A
        quality
        Enables AI models to perform MySQL database operations through a standardized interface, supporting secure connections, query execution, and comprehensive schema management.
        Last updated -
        7
        64
        25
        JavaScript
      • -
        security
        F
        license
        -
        quality
        Facilitates 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
        JavaScript
      • A
        security
        A
        license
        A
        quality
        Connect 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 -
        9
        5
        14
        TypeScript
        MIT License
      • -
        security
        F
        license
        -
        quality
        Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
        Last updated -
        Python
        • Linux
        • Apple

      View all related MCP servers

      MCP directory API

      We provide all the information about MCP servers via our MCP API.

      curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiangma9712/mysql-mcp-server'

      If you have feedback or need assistance with the MCP directory API, please join our Discord server