Cover image
Try Now
2025-04-12

这是一家MCP服务器,涉及从MySQL数据库读取数据。

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

MySQLReader

这是一个用于读取MySQL数据库的MCP服务,基于安全性考量该MCP服务仅提供对于数据库的查询操作,增删改功能暂不支持。本服务的数据库功能均基于pymysql库实现,关于认证方式,本服务支持将数据库用户名密码存储至环境变量(ev)、.txt文件(file)和使用RSA算法加密的.enc文件(efile)三种方式供服务使用。

安装

step 0:安装uv以管理Python

pip install uv

step 1:克隆仓库至本地

本文克隆路径为 D:\\Project

step 2:安装依赖

cd MySQLReader # 进入项目
uv sync # 同步环境
.venv\Scripts\activate # 激活虚拟环境

用法

mysql.py脚本用法如下:

usage: mysql_reader.py [-h] [--authentication-method {ev,file,efile}]
                       [--file-path FILE_PATH] [--evname-user EVNAME_USER]
                       [--evname-pwd EVNAME_PWD]
                       [--private_key_file_name PRIVATE_KEY_FILE_NAME]
                       host db
  • host,必要参数,此参数为数据库地址,如:localhost
  • db,必要参数,此参数为数据库名,如:mysql
  • --authentication-method为认证方式,其值只能从ev、file和efile中选取。
  • --evname-user为用户名存储的环境变量名,当认证方式为ev时系统从--evname-user指示的环境变量中 取用户名。
  • --evname-pwd为密码存储的环境变量名,当认证方式为ev时系统从--evname-pwd指示的环境变量中 取密码。
  • --file-path为文件路径,当认证方式为file或efile时,此参数指示 用户名和密码存储的文件位置。
  • --private_key_file_name为密钥路径,当认证方式为efile时,系统从此参数指示的路径读取密钥。

在Claude Desktop上的用法

添加本服务到你的claude_desktop_config.json文件中

{
    "mcpServers": {
        "mysql_reader": {
            "command": "uv",
            "args": [
                "--directory",
                "Path\to\your\MySQLReader",
                "run",
                "mysql_reader.py",
                "your_database_host",
                "your_database",
                "--authentication-method",
                "ev" # 这是默认值可不填
            ]
        }
    }
}

认证方法 --authentication-method的说明

本服务支持如下三种认证方式:

  • ev:将用户名和密码存储到环境变量中供服务使用。
  • file:将用户名和密码显式的存储到某一txt文件中供服务使用。
  • efile:将用户名和密码加密存储到某一.enc文件中供服务使用。 下面将详细介绍三种认证方式下claude_desktop_config.json的写法。

1.环境变量ev

本方法为--authentication-method的默认值,此时系统会从--evname-user--evname-pwd指示的环境变量中读取用户名和密码,--evname-user--evname-pwd的默认值分别为:DB_USERNAME和DB_PASSWORD。此方法下,claude_desktop_config.json示例如下:

{
    "mcpServers": {
        "mysql_reader": {
            "command": "uv",
            "args": [
                "--directory",
                "Path\to\your\MySQLReader",
                "run",
                "mysql_reader.py",
                "your_database_host",
                "your_database",
                "--authentication-method",
                "ev" # 这是默认值可不填,
                "--evname-user",
                "your_username_environment_variable",
                "--evname-pwd",
                "your_password_environment_variable",
                
            ]
        }
    }
}

2.显式文件file

--authentication-method传入file时,系统会从--file-path指示的文件中读取出用户名和密码。此方法下,系统会从文件中逐行读取,读取到行以username:开头(不区分大小写)时则认为:后均为用户名,读取到行以password:开头(不区分大小写)时则认为:后均为密码。需要注意的是此方法只能显式的将用户名和密码存储在文件中,并 不安全 ,所以不推荐使用本方法。

{
    "mcpServers": {
        "mysql_reader": {
            "command": "uv",
            "args": [
                "--directory",
                "Path\to\your\MySQLReader",
                "run",
                "mysql_reader.py",
                "your_database_host",
                "your_database",
                "--authentication-method",
                "file",
                "--file-path",
                "your_file_path"
            ]
        }
    }
}

3.加密文件efile

--authentication-method传入efile时,系统会从--file-path指示的文件中读取出加密后的用户名和密码,然后使用--private_key_file_name指示的私钥解密出用户名和密码用以连接数据库。本方法的操作流程如下:

  • 1.使用脚本RSA_key_generator.py加密用户名和密码。
  • 2.将生成的加密数据文件和密钥写入json文件

示例如下:

{
    "mcpServers": {
        "mysql_reader": {
            "command": "uv",
            "args": [
                "--directory",
                "Path\to\your\MySQLReader",
                "run",
                "mysql_reader.py",
                "your_database_host",
                "your_database",
                "--authentication-method",
                "file",
                "--file-path",
                "your_enc_file_path",
                "--private_key_file_name"
                "your_pem_file_path"
            ]
        }
    }
}

加密脚本RSA_key_generator.py的使用方法

usage: RSA_key_generator.py [-h] [--use-new-key USE_NEW_KEY]
                            [--public_key_file_name PUBLIC_KEY_FILE_NAME]
                            [--private_key_file_name PRIVATE_KEY_FILE_NAME]
                            [--encrypted_file_name ENCRYPTED_FILE_NAME]
                            username password
  • username,需要加密的用户名。
  • password,需要加密的密码。
  • --use-new-key,布尔值,是否使用新的密钥对,如果为true则会生成新密钥对加密,为false则使用 --public_key_file_name指示的公钥加密,默认为true。
  • --public_key_file_name,公钥文件名,会自动填充.pem后缀名。当--use-new-key为true时生成的 新公钥为该名,为false时则读取该路径指示的公钥加密,默认值为public_key.pem。
  • --private_key_file_name,私钥文件名,会自动填充.pem后缀名。当--use-new-key为true时生成的 新私钥为该名,为false时此参数被忽略,默认值为private_key.pem。
  • --encrypted_file_name,加密后的用户名和密码存储的文件,默认值为config.enc。

示例:

  • 生成新的密钥对
    • 命令(cmd,Linux需要将^换为\):
     python RSA_key_generator.py your_username your_password ^
    --public_key_file_name your_public_key_file_name ^
    --private_key_file_name your_private_key_file_name ^
    --encrypted_file_name your_encrypted_file_name
    
    • 结果: 生成文件your_public_key_file_name.pemyour_private_key_file_name.pemyour_encrypted_file_name.enc
  • 使用已有密钥对加密(假设已有公钥文件名为your_public_key_file_name.pem
    • 命令(cmd,Linux需要将^换为\):
       python RSA_key_generator.py your_username your_password ^
      --use-new-key false ^
      --public_key_file_name your_public_key_file_name ^
      --encrypted_file_name your_encrypted_file_name
      
    • 结果: 生成文件your_encrypted_file_name.enc

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Lists Tailwind CSS classes in monospaced font

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • Daren White
  • A supportive coach for mastering all Spanish tenses.

  • J. DE HARO OLLE
  • Especialista en juegos de palabras en varios idiomas.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • HiveNexus
  • 一个适用于中小型团队的AI聊天机器人,支持DeepSeek,Open AI,Claude和Gemini等车型。 专为中小团队设计的ai聊天应用,支持deepSeek,打开ai,claude,双子座等模型。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

    Reviews

    1 (1)
    Avatar
    user_ALr8kC6A
    2025-04-16

    MySQLReader is an excellent tool for effortlessly extracting data from MySQL databases. Developed by ChenRongpeng1998, it provides a seamless experience with its intuitive interface and robust performance. Highly recommend for anyone needing reliable database reading capabilities. Check it out at https://github.com/ChenRongpeng1998/MySQLReader.