mcp-mysql
一个提供MySQL数据库操作的模型上下文协议服务器。该服务器使AI模型能够通过标准化接口与MySQL数据库进行交互。支持对数据库的所有操作。
claude mcp add --transport stdio huangfeng19820712-mcp-mysql-server npx -y @fhuang/mcp-mysql-server mysql://user:password@localhost:port/database \ --env MYSQL_HOST="your_host" \ --env MYSQL_USER="your_user" \ --env MYSQL_DATABASE="your_database" \ --env MYSQL_PASSWORD="your_password"
How to use
The @fhuang/mcp-mysql-server provides a Model Context Protocol (MCP) server that enables AI models to interact with a MySQL database through a standardized set of tools. It supports establishing a database connection, running queries with optional prepared statements, and performing common database operations such as listing tables, describing table structures, and explaining query plans. The available tools include: connect_db to establish a MySQL connection, query to run SELECT statements with optional parameters, execute to run INSERT/UPDATE/DELETE statements with optional parameters, list_tables to enumerate all tables in the connected database, describe_table to inspect a table’s schema, show_statement to run SHOW commands (e.g., SHOW VARIABLES), and explain to obtain an execution plan for a given query. These tools are invoked via a small helper use_mcp_tool function, which takes the server name, tool name, and arguments. By configuring the MCP with the provided environment variables, you can securely manage credentials and connect to your database without embedding sensitive data in prompts. The system emphasizes prepared statements for security, automatic connection management, and robust error handling.
How to install
Prerequisites:
- Node.js and npm (or pnpm) installed on your machine
- Access to npm npx tool or Smithery if using the Smithery workflow
Installation options:
-
Smithery automatic installation (recommended if you use Smithery):
- Run: npx -y @smithery/cli install @fhuang/mcp-mysql-server --client claude
- This will provision the MCP server for use with Claude
-
Manual installation (local usage):
- Run: npx @fhuang/mcp-mysql-server
- This starts the MCP server directly via npx
-
Optional configuration in your MCP settings:
- Add an mcpServers entry with the mysql server name, using the npx command and providing connection details via environment variables as needed.
Example steps:
- Ensure Node.js is installed (check with node -v and npm -v).
- Install or run the server as shown above.
- In your MCP configuration, specify the server under mcpServers with command as npx and include the appropriate arguments and environment variables for your database credentials.
Additional notes
Tips and considerations:
- Use prepared statements to mitigate SQL injection risks; the server documentation highlights support for prepared parameters.
- Store sensitive credentials in environment variables (MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE) rather than in command prompts.
- If you need to test connectivity, start by establishing a connection with connect_db, then progressively run query, execute, and other tools.
- When using npx, you may leverage environment variable prefixes (e.g., OPENAI_API_KEY) as shown in evals examples to run evaluations alongside the MCP server.
- For production deployments, consider mounting a configuration file or secret store to supply the env vars securely and restrict access to the MCP server.
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.