Skip to main content
Glama
MySQL MCP Server

MySQL MCP Server

by ImRieul

@imrieul/mysql-mcp-server

한국어 | 日本語 | 中文 | Español | Português | Français | Русский

A simple MySQL MCP server.

Features

  • LLM-friendly — compact column/row format, auto LIMIT, error hints with next-action suggestions

  • Bulk schema — describe_all_tables returns entire DB schema in one call

  • Read-only mode — app-level prefix check + DB-level SET SESSION TRANSACTION READ ONLY

  • Query timeout — Promise.race() based timeout with guaranteed connection cleanup

  • SSL support — one env var to enable encrypted connections

  • Minimal — 3 dependencies, zero config required

Related MCP server: tokenlite-mysql-mcp

Quick Start

Add to your MCP config (.mcp.json or claude_desktop_config.json):

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@imrieul/mysql-mcp-server"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "your-database"
      }
    }
  }
}

Or with a connection string:

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@imrieul/mysql-mcp-server", "mysql://root:password@localhost:3306/mydb"]
    }
  }
}

Codex

Codex uses TOML config, not mcpServers JSON. Add this to ~/.codex/config.toml or a project-scoped .codex/config.toml:

[mcp_servers.mysql]
command = "npx"
args = ["-y", "@imrieul/mysql-mcp-server"]

[mcp_servers.mysql.env]
MYSQL_HOST = "localhost"
MYSQL_PORT = "3306"
MYSQL_USER = "root"
MYSQL_PASSWORD = "your-password"
MYSQL_DATABASE = "your-database"

opencode

Add this to opencode.json or opencode.jsonc:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "mysql": {
      "type": "local",
      "command": ["npx", "-y", "@imrieul/mysql-mcp-server"],
      "enabled": true,
      "environment": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "your-database"
      }
    }
  }
}

Read-only mode with SSL

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@imrieul/mysql-mcp-server", "--readonly"],
      "env": {
        "MYSQL_HOST": "db.example.com",
        "MYSQL_USER": "readonly_user",
        "MYSQL_PASSWORD": "password",
        "MYSQL_DATABASE": "production",
        "MYSQL_SSL": "true",
        "MYSQL_QUERY_TIMEOUT": "10000"
      }
    }
  }
}

Tools

Tool

Description

Read-only mode

query

Execute SELECT, SHOW, DESCRIBE, EXPLAIN

Allowed

execute

Execute INSERT, UPDATE, DELETE, DDL

Blocked

list_databases

List all databases

Allowed

list_tables

List tables in a database

Allowed

describe_table

Show table schema

Allowed

describe_all_tables

Show all table schemas at once

Allowed

Configuration

Environment variables

Variable

Required

Default

Description

MYSQL_HOST

Yes

—

MySQL host

MYSQL_USER

Yes

—

MySQL user

MYSQL_PASSWORD

Yes

—

MySQL password

MYSQL_PORT

No

3306

MySQL port

MYSQL_DATABASE

No

—

Default database

MYSQL_READONLY

No

false

Read-only mode

MYSQL_MAX_ROWS

No

100

Auto LIMIT for SELECT queries

MYSQL_QUERY_TIMEOUT

No

30000

Query timeout in ms (0 to disable)

MYSQL_SSL

No

false

Enable SSL connection

Connection string

mysql://user:password@host:port/database

Passed as the first CLI argument. Takes priority over environment variables.

License

MIT

Available Tools

7 tools
add_commentA

Safely add a comment to a table or column. This tool only modifies comments — it cannot alter table structure, column types, or data. Set dryRun=true to preview the generated SQL without executing it. Use describe_table first to verify column names. Not available in read-only mode.

Inputs: table (required), comment (required), column, dryRun, +1 more.

describe_all_tablesA

Show the schema of all tables at once. Much more efficient than calling describe_table for each table individually. Warning: response can be large for databases with many tables — prefer describe_table for specific tables when possible.

Inputs: database.

describe_tableA

Show the schema/structure of a table, including column names, types, constraints, and comments. Use this before writing queries to ensure correct column names and types. For inspecting all tables at once, use describe_all_tables instead.

Inputs: table (required), database.

executeA

Execute a data modification SQL statement (INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, etc.). Set dryRun=true to validate without executing — uses EXPLAIN for DML, or previews the SQL for DDL. Always confirm destructive operations (DROP, TRUNCATE, DELETE without WHERE) with the user before executing. Not available in read-only mode.

Inputs: sql (required), dryRun.

list_databasesA

List all databases on the MySQL server. Use this as a starting point to discover available databases before querying. Returns a JSON array of database names.

Inputs: no named parameters.

list_tablesA

List all tables in the specified database (or the current database if not specified). Includes table comments when available. Use this before describe_table to find the exact table name.

Inputs: database.

queryA

Execute a read-only SQL query (SELECT, SHOW, DESCRIBE, EXPLAIN). LIMIT is auto-appended to SELECT/WITH queries without one (default: server maxRows). Prefer specific columns over SELECT * to reduce response size. For data modification, use the "execute" tool instead.

Inputs: sql (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 7 tools

    Disambiguation5/5

    All tools have clearly distinct purposes: listing databases, listing tables, describing schemas (single or all), querying read-only, executing modifications, and adding comments. No overlap or confusion.

    Naming Consistency5/5

    All tool names use a consistent verb_noun pattern in snake_case (e.g., list_databases, describe_table), with clear verbs like add, describe, execute, list, query. The naming is uniform and predictable.

    Tool Count5/5

    With 7 tools, the server is well-scoped for MySQL database interactions. Each tool addresses a core operation without redundancy, and the count is appropriate for the domain.

    Completeness5/5

    The tool set covers the full lifecycle: discovery (list databases/tables), schema inspection (describe), data querying (query), modifications (execute), and metadata updates (add_comment). The execute tool handles any SQL needed, so there are no gaps.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Secure and token-efficient MySQL MCP server built specifically for AI agents. Prevents hallucinations, optimizes context windows and blocks dangerous queries.
      5
      284 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A secure and efficient MCP server for MySQL database operations, enabling LLMs to execute SQL queries with read-only access by default and optional write permissions.
      22 PyPI
      3
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A multi-database MCP server that enables LLMs to safely interact with MySQL, PostgreSQL, SQLite, and others through a unified tool interface, with permission modes and schema resources.
      10
      44
      MIT