Get the FREE Ultimate OpenClaw Setup Guide →

mysql

MCP MySQL Server 是一个基于 @modelcontextprotocol/sdk 的 MySQL 工具服务,支持 SQL 查询、表结构获取、连接检测等功能,适用于 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 tickhaijun-mysql-mcp-server node src/index.js

How to use

This MCP server exposes a MySQL toolset based on the @modelcontextprotocol/sdk. It provides three core tools to work with your database: execute_sql for running SQL queries (SELECT, INSERT, UPDATE, DELETE), get_tables_info to retrieve the structure of all tables and their columns, and get_connection_status to verify that the MySQL connection is healthy. The server is designed with safety checks to prevent dangerous operations and SQL injections, making it suitable for AI assistants and automation tasks where you need to run SQL through a structured MCP interface.

To use these tools, start the server locally (or in your preferred environment) and connect to it using the MCP protocol. You can then invoke execute_sql with your SQL statements and parameters, call get_tables_info to inspect database schemas, or use get_connection_status to confirm connectivity before performing operations. Configuration is flexible via environment variables or a .env file, allowing you to tailor host, port, and credentials without hard-coding them into your requests.

How to install

Prerequisites:

  • Node.js 18+ installed on your system
  • npm (comes with Node.js) or yarn

Installation steps:

  1. Clone the repository: git clone https://github.com/yourname/mcp-mysql-server.git cd mcp-mysql-server

  2. Install dependencies: npm install

  3. Configure the database connection (optional but recommended):

    • Create a .env file at the project root with: DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD=yourpassword DB_NAME=yourdatabase
  4. Start the MCP server: node src/index.js

  5. Verify the server is running by checking logs or connecting via the MCP client.

Additional notes

Environment variables fall back to defaults defined in src/config.js, but you should provide your own DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, and DB_NAME to connect to your MySQL instance. The server uses mysql2/promise for asynchronous operations and includes validation to prevent dangerous queries or injections. If you encounter connection issues, ensure MySQL accepts connections from your host and that user credentials are correct. You can adjust security settings through the config file and environment variables. The MCP server exposes three tools: execute_sql, get_tables_info, and get_connection_status; interactions should be performed through the MCP client adhering to the expected payload structure.

Related MCP Servers

Sponsor this space

Reach thousands of developers