Skip to main content
Glama

MySQL MCP Server

MySQL MCP サーバー

MySQL データベースと対話するための MCP サーバー。

このサーバーは、読み取り専用クエリ (query) と、最終的にロールバックされる書き込みクエリ (test_execute) の実行をサポートしています。

設定

環境変数

~/.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

host.docker.internal 、Docker コンテナからホストマシンのサービスにアクセスするための特別な DNS 名です。ホストマシン上で実行されている MySQL サーバーに接続する場合は、この設定を使用してください。別の MySQL サーバーに接続する場合は、適切なホスト名に変更してください。

mcp.json 構成

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

使用法

サーバーの起動

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

:OrbStackを使用している場合は、 host.docker.internalが自動的にサポートされるため、 --add-hostオプションは省略できます。Docker Desktopも通常はこれを自動的にサポートしますが、信頼性を高めるために--add-hostオプションを追加することをお勧めします。

利用可能なコマンド

1. 読み取り専用クエリを実行する
{ "type": "query", "payload": { "sql": "SELECT * FROM your_table" } }

応答:

{ "success": true, "data": [ { "id": 1, "name": "example" } ] }
2. クエリ実行のテスト
{ "type": "test_execute", "payload": { "sql": "UPDATE your_table SET name = 'updated' WHERE id = 1" } }

応答:

{ "success": true, "data": "The UPDATE SQL query can be executed." }
3. リストテーブル
{ "type": "list_tables" }

応答:

{ "success": true, "data": ["table1", "table2", "table3"] }
4. 表の説明
{ "type": "describe_table", "payload": { "table": "your_table" } }

応答:

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

実装の詳細

  • TypeScriptで実装
  • mysql2 パッケージを使用
  • Dockerコンテナとして実行
  • 標準入力を通じてJSONコマンドを受け入れる
  • 標準出力を通じてJSONレスポンスを返します
  • ホスト MySQL に接続するためにhost.docker.internalを使用します (OrbStack と Docker Desktop の両方と互換性があります)

セキュリティに関する考慮事項

  • 機密情報の管理に環境変数を使用する
  • SQLインジェクションの防止は実装者の責任である
  • 実稼働環境での使用には適切なネットワーク構成が必要
  • ホストマシンのサービスに接続する際に必要な適切なファイアウォール設定

You must be authenticated.

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.

JSON コマンドを介して MySQL データベースと対話できるようにし、読み取り専用クエリ、書き込みクエリのテスト実行、Docker を介したテーブル情報の取得をサポートします。

  1. 設定
    1. 環境変数
    2. mcp.json 構成
  2. 使用法
    1. サーバーの起動
    2. 利用可能なコマンド
  3. 実装の詳細
    1. セキュリティに関する考慮事項

      Related MCP Servers

      • -
        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 -
        2
        JavaScript
      • -
        security
        A
        license
        -
        quality
        A Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read-only queries.
        Last updated -
        5,426
        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
      • -
        security
        -
        license
        -
        quality
        An MCP server that allows working with MySQL databases by providing tools for executing read-only SQL queries, getting table schemas, and listing database tables.
        Last updated -
        1
        JavaScript

      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