Skip to main content
Glama

mysql_mcp_server

by wenb1n-dev

mcp_mysql_server

導入

mcp_mysql_server_pro は、MySQL CRUD 操作だけではなく、データベース異常分析機能も備えており、開発者がカスタム ツールを使用して簡単に拡張できます。

  • STDIOモードとSSEモードの両方をサポート
  • 「;」で区切られた複数の SQL 実行をサポートします。
  • テーブルコメントに基づいてデータベーステーブル名とフィールドのクエリをサポートします
  • SQL実行プラン分析をサポート
  • 中国語フィールドからピンインへの変換をサポート
  • テーブルロック分析をサポート
  • データベースの健全性状態分析をサポート
  • 読み取り専用、書き込み、管理者の 3 つのロールによる権限制御をサポートします
    "readonly": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN"], # Read-only permissions "writer": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE"], # Read-write permissions "admin": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"] # Administrator permissions
  • プロンプトテンプレートの呼び出しをサポート

ツールリスト

ツール名説明
実行SQL権限設定に基づいて["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"]コマンドを実行できるSQL実行ツール
中国語のイニシャルを取得する中国語のフィールド名をピンインの頭文字に変換する
get_db_health_runningMySQLのヘルスステータス(接続ステータス、トランザクションステータス、実行ステータス、ロックステータス検出)を分析
get_table_descテーブル名に基づいてデータベース内のテーブル構造を検索し、複数のテーブルクエリをサポートします。
テーブルインデックスを取得するテーブル名に基づいてデータベース内のテーブルインデックスを検索し、複数のテーブルクエリをサポートします。
get_table_lock現在のMySQLサーバーに行レベルロックまたはテーブルレベルロックがあるかどうかを確認します
テーブル名を取得するテーブルのコメントと説明に基づいてデータベース内のテーブル名を検索します
get_db_health_index_usage現在接続している MySQL データベースのインデックス使用状況を取得します。これには、冗長なインデックス状況、パフォーマンスの低いインデックス状況、クエリ時間が 30 秒を超える上位 5 つの未使用のインデックス状況が含まれます。

プロンプトリスト

プロンプト名説明
MySQLプロンプトの分析これはMySQL関連の問題を分析するためのプロンプトです
クエリテーブルデータプロンプトこれは、ツールを使用してテーブルデータをクエリするためのプロンプトです。説明が空の場合、MySQLデータベースクエリアシスタントとして初期化されます。

使用方法

SSEモード

  • uvを使用してサービスを開始します

カーソル、クラインなどの MCP クライアント ツールに次のコンテンツを追加します。

mcp json は次のようになります。

{ "mcpServers": { "operateMysql": { "name": "operateMysql", "description": "", "isActive": true, "baseUrl": "http://localhost:9000/sse" } } }

.env ファイルの内容を変更して、データベース接続情報をデータベースの詳細に更新します。

# MySQL Database Configuration MYSQL_HOST=192.168.xxx.xxx MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=root MYSQL_DATABASE=a_llm MYSQL_ROLE=readonly # Optional, default is 'readonly'. Available values: readonly, writer, admin

開始コマンド:

# Download dependencies uv sync # Start uv run server.py

STDIOモード

カーソル、クラインなどの MCP クライアント ツールに次のコンテンツを追加します。

mcp json は次のようになります。

{ "mcpServers": { "operateMysql": { "isActive": true, "name": "operateMysql", "command": "uv", "args": [ "--directory", "G:\\python\\mysql_mcp\\src", # Replace this with your project path "run", "server.py", "--stdio" ], "env": { "MYSQL_HOST": "192.168.xxx.xxx", "MYSQL_PORT": "3306", "MYSQL_USER": "root", "MYSQL_PASSWORD": "root", "MYSQL_DATABASE": "a_llm", "MYSQL_ROLE": "readonly" # Optional, default is 'readonly'. Available values: readonly, writer, admin } } } }

カスタムツール拡張機能

  1. ハンドル パッケージに新しいツール クラスを追加し、BaseHandler から継承し、get_tool_description メソッドと run_tool メソッドを実装します。
  2. init.pyに新しいツールをインポートして、サーバーで使用できるようにします。

  1. 新しいテーブルを作成し、データを挿入します。プロンプトの形式は次のとおりです。
# Task Create an organizational structure table with the following structure: department name, department number, parent department, is valid. # Requirements - Table name: t_admin_rms_zzjg - Field requirements: string type uses 'varchar(255)', integer type uses 'int', float type uses 'float', date and time type uses 'datetime', boolean type uses 'boolean', text type uses 'text', large text type uses 'longtext', large integer type uses 'bigint', large float type uses 'double' - Table header needs to include primary key field, serial number XH varchar(255) - Table must include these fixed fields at the end: creator-CJR varchar(50), creation time-CJSJ datetime, modifier-XGR varchar(50), modification time-XGSJ datetime - Field naming should use tool return content - Common fields need indexes - Each field needs comments, table needs comment - Generate 5 real data records after creation
  1. テーブルのコメントに基づいてデータをクエリします。次のようにプロンプトが表示されます。
Query Zhang San's data from the user information table
  1. 遅い SQL を分析し、次のようにプロンプトを表示します。
select * from t_jcsjzx_hjkq_cd_xsz_sk xsz left join t_jcsjzx_hjkq_jcd jcd on jcd.cddm = xsz.cddm Based on current index situation, review execution plan and provide optimization suggestions in markdown format, including table index status, execution details, and optimization recommendations
  1. SQL デッドロックの問題を分析し、次のようにプロンプトを表示します。
update t_admin_rms_zzjg set sfyx = '0' where xh = '1' is stuck, please analyze the cause
  1. 健康状態プロンプトを次のように分析します
Check the current health status of MySQL

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

STDIOモードとSSEモードのサポートを追加 「;」で区切られた複数のSQL実行のサポートを追加 テーブルコメントに基づいてデータベーステーブル名とフィールドをクエリする機能を追加 SQL実行プラン分析を追加 ピンイン変換に中国語フィールドを追加

  1. 導入
    1. ツールリスト
      1. プロンプトリスト
        1. 使用方法
          1. SSEモード
          2. STDIOモード
        2. カスタムツール拡張機能

            Related MCP Servers

            • -
              security
              A
              license
              -
              quality
              Facilitates interaction with Microsoft SQL Server Express, supporting database operations such as querying, table management, and schema inspection via natural language MCP commands.
              Last updated -
              1
              Python
              MIT License
            • -
              security
              F
              license
              -
              quality
              A server that enables interaction with PostgreSQL, MySQL, MariaDB, or SQLite databases through Claude Desktop using natural language queries.
              Last updated -
              Python
            • -
              security
              F
              license
              -
              quality
              A natural language interface that allows Claude to execute SQL queries on your local MySQL databases, enabling database interaction using natural language.
              Last updated -
              2
              Python
              • Linux
              • Apple
            • -
              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/wenb1n-dev/mysql_mcp_server_pro'

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