Get the FREE Ultimate OpenClaw Setup Guide →

mcp-mysql

一个提供MySQL数据库操作的模型上下文协议服务器。该服务器使AI模型能够通过标准化接口与MySQL数据库进行交互。支持对数据库的所有操作。

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. 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
  2. Manual installation (local usage):

    • Run: npx @fhuang/mcp-mysql-server
    • This starts the MCP server directly via npx
  3. 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

Sponsor this space

Reach thousands of developers