mysql_mcp_server

by wenb1n-dev
Verified

hybrid server

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

Integrations

  • Enables configuration of MySQL database connection settings (host, port, user, password, database) through environment variables stored in .env files.

  • Allows executing SQL queries against MySQL databases, supporting multiple SQL statements, table name/field querying based on comments, SQL execution plan analysis, and Chinese to pinyin field conversion.

mcp_mysql_server

소개

mcp_mysql_server_pro는 MySQL CRUD 작업에만 사용되는 것이 아니라 데이터베이스 이상 분석 기능도 포함하고 있으며 개발자가 사용자 정의 도구를 사용하여 쉽게 확장할 수 있도록 해줍니다.

  • STDIO 및 SSE 모드를 모두 지원합니다
  • ";"로 구분된 여러 SQL 실행을 지원합니다.
  • 테이블 주석을 기반으로 데이터베이스 테이블 이름 및 필드 쿼리를 지원합니다.
  • SQL 실행 계획 분석을 지원합니다
  • 중국어 필드를 병음으로 변환 지원
  • 테이블 잠금 분석 지원
  • 읽기 전용, 작성자, 관리자의 세 가지 역할로 권한 제어를 지원합니다.지엑스피1

사용 지침

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. handles 패키지에 새 도구 클래스를 추가하고 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

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

STDIO 모드 및 SSE 모드에 대한 지원 추가 ";"로 구분된 여러 SQL 실행에 대한 지원 추가 테이블 주석을 기반으로 데이터베이스 테이블 이름 및 필드를 쿼리하는 기능 추가 SQL 실행 계획 분석 추가 중국어 필드를 병음으로 변환 추가

  1. Introduction
    1. Usage Instructions
      1. SSE Mode
      2. STDIO Mode
    2. Custom Tool Extensions
      1. Examples
        ID: 3w3wd880vr