Skip to main content
Glama
mysql_mcp_server

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
  • プロンプトテンプレートの呼び出しをサポート

Related MCP server: MySQL MCP Server Pro

ツールリスト

ツール名

説明

実行SQL

権限設定に基づいて["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"]コマンドを実行できるSQL実行ツール

中国語のイニシャルを取得する

中国語のフィールド名をピンインの頭文字に変換する

get_db_health_running

MySQLのヘルスステータス(接続ステータス、トランザクションステータス、実行ステータス、ロックステータス検出)を分析

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

Available Tools

5 tools
execute_sqlC

在MySQL5.6s数据库上执行SQL

Inputs: query (required).

get_chinese_initialsB

创建表结构时,将中文字段名转换为拼音首字母字段

Inputs: text (required).

get_table_descC

根据表名搜索数据库中对应的表结构,支持多表查询

Inputs: text (required).

get_table_indexC

根据表名搜索数据库中对应的表索引,支持多表查询

Inputs: text (required).

get_table_nameB

根据表中文名搜索数据库中对应的表名

Inputs: text (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 5 tools

    Disambiguation3/5

    The tools have distinct primary purposes (SQL execution, field name conversion, table structure/index/name retrieval), but there is some overlap between get_table_desc, get_table_index, and get_table_name as they all involve table metadata retrieval, which could cause confusion about which to use for specific queries. Descriptions help clarify, but the boundaries are not perfectly clear.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern using snake_case (e.g., execute_sql, get_table_desc), with no deviations in style or convention. This predictability makes it easy for agents to understand and navigate the tool set.

    Tool Count4/5

    With 5 tools, the count is reasonable and well-scoped for a MySQL server, covering core operations like SQL execution and table metadata access. It is slightly lean but not insufficient, as it avoids bloat while providing essential functionality.

    Completeness2/5

    The tool set is severely incomplete for a MySQL database server. It lacks basic CRUD operations (e.g., create_table, update_data, delete_table), data manipulation beyond raw SQL, and lifecycle management tools, leaving significant gaps that will hinder agent workflows and cause failures in typical database interactions.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A universal SQLite database management tool that enables SQL query execution through MCP protocol. Supports SELECT/INSERT/UPDATE/DELETE/CREATE operations with built-in SQL injection protection across stdio, SSE, and streamable-http communication modes.
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Provides comprehensive MySQL database operations including CRUD, performance optimization, health analysis, and anomaly detection. Supports multiple connection modes, OAuth2.0 authentication, and role-based permissions for database management through natural language.
      9
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Multi-database management tool and MCP server supporting MySQL, PostgreSQL, SQLite, and Dameng DM8, enabling AI assistants to query and manage databases via stdio or HTTP.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables SQL queries, schema exploration, and Oracle sequence management across multiple databases including Oracle, OceanBase, and DolphinDB. Supports multiple environments with secure password handling.
      -