SQL MCP Server for Claude Desktop

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Enables secure connections to local MySQL databases, supporting all types of SQL queries (SELECT, INSERT, UPDATE, DELETE, etc.) through natural language interaction

Claude 桌面版的 SQL MCP 服务器

通过 Claude Desktop 提供与本地 MySQL 数据库的自然语言接口。此 MCP(机器通信协议)服务器允许 Claude 在您的本地 MySQL 数据库上执行 SQL 查询,从而让您能够使用自然语言与数据库进行交互。

特征

  • 通过 Claude 将自然语言转换为 SQL 查询
  • 与本地 MySQL 数据库的安全连接
  • 支持多种数据库
  • 数据一致性的事务管理
  • 连接池可实现更好的性能
  • 支持所有类型的 SQL 查询(SELECT、INSERT、UPDATE、DELETE 等)

先决条件

  • Python 3.8 或更高版本
  • MySQL 服务器已安装并正在运行
  • Claude桌面应用程序
  • 虚拟环境(推荐)

安装

  1. 克隆此存储库:
git clone git@github.com:meanands/mysql-mcp.git cd mysql-mcp
  1. 创建并激活虚拟环境:
# For macOS/Linux python -m venv venv source venv/bin/activate # For Windows python -m venv venv venv\Scripts\activate
  1. 安装依赖项:
pip install -r requirements.txt
  1. 使用您的 MySQL 凭据在项目根目录中创建一个.env文件:
MYSQL_HOST=localhost MYSQL_USER=your_username MYSQL_PASSWORD=your_password
  1. 更新run.sh中的目录路径:
# Open run.sh and replace this line: cd /Users/yourname/code/sql-mcp # with your actual project directory path, for example: cd /Users/yourname/projects/mysql-mcp
  1. 使运行脚本可执行:
chmod +x run.sh

Claude Desktop中的配置

  1. 打开Claude Desktop的MCP配置
  2. 添加以下配置:
{ "sql": { "command": "/absolute/path/to/your/mysql-mcp/run.sh" } }

/absolute/path/to/your/mysql-mcp替换为项目目录的实际绝对路径。

用法

配置完成后,您可以通过 Claude Desktop 使用自然语言与数据库进行交互。示例:

  1. 选择数据库并创建表:
Use the 'employees' database and create a table for storing employee information with fields for name, email, and department.
  1. 插入数据:
Insert a new employee named John Doe with email john.doe@example.com in the Engineering department.
  1. 查询数据:
Show me all employees in the Engineering department.

重要提示

  • 始终在 run.sh 脚本和 Claude Desktop 配置中使用绝对路径
  • 使用 MCP 服务器前,请确保 MySQL 服务器正在运行
  • 确保 .env 文件的安全,切勿将其提交到版本控制
  • MCP 服务器使用连接池,默认池大小为 5 个连接

故障排除

  1. 如果出现“连接被拒绝”错误,请确保 MySQL 服务器正在运行
  2. 如果出现身份验证错误,请在 .env 文件中验证您的凭据
  3. 对于权限错误,请确保您的 MySQL 用户对您尝试执行的操作具有适当的权限

安全注意事项

  • 将敏感凭证存储在 .env 文件中
  • 使用具有适当权限的 MySQL 用户(避免使用 root)
  • 保持虚拟环境和依赖项保持最新
  • 如果访问非本地主机的 MySQL 服务器,请考虑网络安全
-
security - not tested
F
license - not found
-
quality - not tested

自然语言界面允许 Claude 在您的本地 MySQL 数据库上执行 SQL 查询,从而实现使用自然语言进行数据库交互。

  1. Features
    1. Prerequisites
      1. Installation
        1. Configuration in Claude Desktop
          1. Usage
            1. Important Notes
              1. Troubleshooting
                1. Security Considerations
                  ID: cs7d9mmpee