Get the FREE Ultimate OpenClaw Setup Guide →

mcp-mysql

A Model Context Protocol server for MySQL database operations

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio f4ww4z-mcp-mysql-server npx -y @f4ww4z/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

This MCP server exposes a MySQL-focused interface that lets AI models interact with a MySQL database through a standardized set of tools. The available tools include: connect_db to establish a database connection using credentials, query to run SELECT statements with optional prepared parameters, execute to run INSERT/UPDATE/DELETE operations with optional prepared parameters, list_tables to enumerate tables in the connected database, and describe_table to fetch a table’s schema. To use these tools, you first ensure the server is running with the proper environment variables (host, user, password, and database) and then invoke the tool functions with the appropriate arguments. When using the provided code examples, you supply the server name (mysql) and the tool name (e.g., query) along with the required arguments, such as SQL statements and parameters. This setup supports secure parameterized queries via prepared statements and handles connection management automatically. You can run eval tests against this server using the mcp-eval workflow, which loads a client and executes the index.ts through the eval runner.

How to install

Prerequisites:

  • Node.js and npm (or npx) installed on your system.
  • Access to the internet to fetch the MCP server package.

Installation steps (via Smithery):

  1. Install the MCP server automatically for a client (e.g., Claude) using Smithery: npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude

Manual installation (no Smithery):

  1. Run the MCP server directly with npx: npx @f4ww4z/mcp-mysql-server

Configuration (example):

  • Create or edit your MCP settings with the following mcpServers entry, replacing credentials as needed:
{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:port/database"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Tip: You can also configure the server in platform-specific config files (Codex, etc.) as shown in the README, using identical command and args values.

Additional notes

Tips and notes:

  • Use prepared statements to guard against SQL injection (supported by the server).
  • Environment variables for MySQL credentials can be supplied via the env block in your MCP configuration or prefixed to the npx command when running evals.
  • The server handles automatic connection cleanup, but ensure network access to your MySQL instance.
  • If you encounter authentication or network errors, double-check host, port, user, and password values, and ensure MySQL permits connections from your environment.
  • When testing, you can leverage the mcp-evals tooling to run a client against the index.ts entry point without rebuilding between tests.

Related MCP Servers

Sponsor this space

Reach thousands of developers