home / mcp / mysql mcp server

MySQL MCP Server

A Model Context Protocol server for MySQL database operations

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "f4ww4z-mcp-mysql-server": {
      "command": "npx",
      "args": [
        "-y",
        "@f4ww4z/mcp-mysql-server",
        "mysql://user:password@localhost:port/database"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "db_user",
        "MYSQL_DATABASE": "my_db",
        "MYSQL_PASSWORD": "secret"
      }
    }
  }
}

You can use this MCP server to enable AI models to perform MySQL database operations through a standardized interface. It handles secure connections, prepared statements, and automatic connection management so you can focus on data tasks like querying and updating your MySQL databases.

How to use

You interact with the MySQL MCP server through an MCP client. Start by configuring your client to connect to the server, then issue common data actions such as connecting to the database, running SELECT queries, performing INSERT/UPDATE/DELETE operations, listing tables, and inspecting table structures. The server automatically manages connections and cleans up resources after each operation, keeping interactions simple and secure.

How to install

Prerequisites: you need Node.js and npm installed on your machine.

Step 1: Install and run the MCP server locally with the npx command.

Step 2: If you want Claude Desktop to use the server automatically, install via the Smithery CLI.

Step 3: Ensure the server is running and reachable from your MCP client.

Additional configuration and usage notes

The server can be configured in your MCP settings with either a direct URL or environment variables for the host, user, password, and database. Use the following configuration shapes to connect via your MCP client.

Configuration

Use one of the following configurations to connect the MCP client to the MySQL MCP server.

{ 
  "mcpServers": {
    "mysql": {
      "type": "stdio",
      "name": "mysql",
      "command": "npx",
      "args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:port/database"]
    }
  }
}

Or, supply credentials via environment variables (recommended for security):

{ 
  "mcpServers": {
    "mysql": {
      "type": "stdio",
      "name": "mysql",
      "command": "npx",
      "args": ["-y", "@f4ww4z/mcp-mysql-server"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Security

The server uses prepared statements to prevent SQL injection and validates queries before execution. Passwords and sensitive data should be provided through environment variables to avoid exposure in configuration files. Connections are automatically closed when operations finish.

Error Handling

If a connection fails, a query is invalid, or a database error occurs, you will receive a detailed error message that guides you to resolve the issue and safe-guard your operations.

Troubleshooting

If you cannot reach the server, verify that the host, port, and database name are correct. Check that environment variables are correctly set when using the env-based configuration. Ensure your MCP client is configured to target the correct server name (mysql) and that the server process is running.

Examples of common actions

The server exposes tools to connect, query, execute updates, list tables, and describe table structures. Use these actions to manage data in your MySQL databases.

Notes

If you want to run evaluations or tests against the server, use the provided eval workflow by setting your API key and invoking the evaluation script as shown in the execution flow.

Available tools

connect_db

Establish a connection to the MySQL database using provided credentials.

query

Execute SELECT queries with optional prepared statement parameters.

execute

Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.

list_tables

List all tables in the connected database.

describe_table

Get the structure of a specific table.