Get the FREE Ultimate OpenClaw Setup Guide →

mysql

在 cursor 工具中通过 mysql mcp 服务读取本地 mysql 库,方便通过 AI 来编程开发

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio lichuanrong7-mysql-mcp-server node server.js \
  --env PORT="3100" \
  --env DB_HOST="你的数据库地址" \
  --env DB_NAME="你的数据库名称" \
  --env DB_PORT="3306" \
  --env DB_USER="你的数据库用户名" \
  --env DB_PASSWORD="你的数据库密码"

How to use

This MCP server implements a MySQL data access layer for Cursor AI using the MCP protocol. It exposes endpoints that allow the AI to execute SQL queries, retrieve table schemas, and inspect or manipulate data via standardized MCP requests. You can access the MCP manifest at /manifest.json and interact with the API through endpoints such as /api/mysql/query for SQL execution and /api/mysql/schema for table structures. To integrate with Cursor, add the service URL http://<your-host>:3100/manifest.json in the MCP extension manager, activate the service, and begin issuing natural-language commands like querying a table, inspecting a schema, or running data operations. The server handles CORS and responds with a consistent API shape suitable for MCP tooling.

How to install

Prerequisites:

  • Node.js 14.x or newer
  • Git (optional for cloning)
  • Access to a MySQL database

Install locally:

  1. Clone the repository
git clone https://github.com/lichuanrong7/mysql-mcp-server.git
cd mysql-mcp-server
  1. Install dependencies
npm install
  1. Configure environment variables Create a .env file with database and server settings, for example:
# 服务器配置
PORT=3100

# 数据库配置
DB_HOST=your-database-host
DB_PORT=3306
DB_USER=your-db-username
DB_PASSWORD=your-db-password
DB_NAME=your-db-name
  1. Run the server
# 开发模式
npm run dev

# 生产模式
npm start

可选:若使用 Docker,构建镜像并通过 Compose 启动:

docker build -t mysql-mcp-server .
docker-compose up -d

Additional notes

Tips and caveats:

  • Ensure your MySQL user has appropriate privileges for the queries you plan to run.
  • The server exposes /manifest.json and /openapi.yaml for MCP tooling; keep these accessible to Cursor.
  • If the service cannot start due to port conflicts, verify that PORT 3100 (or configured port) is free.
  • For production deployments, consider securing DB credentials (e.g., using a secrets manager) and enabling TLS as needed.
  • Common issues: invalid DB credentials, network/firewall blocks to the database, or missing environment variables. Check logs under the project logs (e.g., logs/mysql-mcp-*.log) for details.

Related MCP Servers

Sponsor this space

Reach thousands of developers