mysql
MCP MySQL Server 是一个基于 @modelcontextprotocol/sdk 的 MySQL 工具服务,支持 SQL 查询、表结构获取、连接检测等功能,适用于 AI 代理、自动化工具等场景。
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:
-
Clone the repository: git clone https://github.com/yourname/mcp-mysql-server.git cd mcp-mysql-server
-
Install dependencies: npm install
-
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
-
Start the MCP server: node src/index.js
-
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
zen
Selfhosted notes app. Single golang binary, notes stored as markdown within SQLite, full-text search, very low resource usage
MCP -Deepseek_R1
A Model Context Protocol (MCP) server implementation connecting Claude Desktop with DeepSeek's language models (R1/V3)
mcp-fhir
A Model Context Protocol implementation for FHIR
mcp
Inkdrop Model Context Protocol Server
mcp-appium-gestures
This is a Model Context Protocol (MCP) server providing resources and tools for Appium mobile gestures using Actions API..
dubco -npm
The (Unofficial) dubco-mcp-server enables AI assistants to manage Dub.co short links via the Model Context Protocol. It provides three MCP tools: create_link for generating new short URLs, update_link for modifying existing links, and delete_link for removing short links.