home / mcp / mysql mcp server

MySQL MCP Server

mcp-server-mysql

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "bibaram-mysql-mcp-server": {
      "command": "node",
      "args": [
        "path/to/mysql-mcp-server/server.js"
      ],
      "env": {
        "DB_HOST": "localhost",
        "DB_NAME": "your_database",
        "DB_PORT": "3306",
        "DB_USER": "root",
        "DB_PASSWORD": "your_password"
      }
    }
  }
}

You can run a MySQL MCP Server to connect to a MySQL database, execute SQL queries, list tables, and inspect table structures through a Model Context Protocol client. This enables you to build data-assisted tooling and automate common database tasks with MCP clients.

How to use

Set up and run the MySQL MCP Server so your MCP client can interact with your MySQL database. You can run predefined commands from the client to execute queries, enumerate tables, and describe table schemas. Start with a local development database or connect to a remote MySQL server, then use the available endpoints to perform operations from your MCP client.

Typical workflows include establishing a connection to a specific database, issuing a query such as selecting rows from a table, listing all tables in the database, and inspecting the columns and data types of a table. You can configure multiple MCP connections to different MySQL instances to manage environments like development, staging, and production.

How to install

Prerequisites you need before installation: Node.js version 18.0.0 or higher and a MySQL server that you can reach from the machine running the MCP server.

git clone https://github.com/bibaram/mysql-mcp-server.git
cd mysql-mcp-server
npm install

If you encounter dependency issues, install the specific MCP SDK and MySQL client as a targeted fix, then re-install dependencies:

npm install @modelcontextprotocol/sdk mysql2

After updating dependencies, install again to ensure all packages are properly wired up:

npm install

Start the server in one of the following ways. If you run directly, set environment variables for the database connection and then start the server with npm:

export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=your_password
export DB_NAME=your_database

npm start

If you configure Claude Desktop to invoke the MCP server, add an MCP entry that launches the server via Node and passes the necessary environment variables:

{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["path/to/mysql-mcp-server/server.js"],
      "env": {
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database"
      }
    }
  }
}

If you need to connect to multiple databases, you can define additional MCP entries for each database connection, providing the appropriate host, user, password, and database name for each environment:

{
  "mcpServers": {
    "mysql-prod": {
      "command": "node",
      "args": ["path/to/mysql-mcp-server/server.js"],
      "env": {
        "DB_HOST": "prod-server.com",
        "DB_USER": "prod_user",
        "DB_PASSWORD": "prod_password",
        "DB_NAME": "production_db"
      }
    },
    "mysql-dev": {
      "command": "node",
      "args": ["path/to/mysql-mcp-server/server.js"],
      "env": {
        "DB_HOST": "localhost",
        "DB_USER": "dev_user",
        "DB_PASSWORD": "dev_password",
        "DB_NAME": "development_db"
      }
    }
  }
}

Available tools

execute_query

Executes a SQL query against the connected MySQL database.

show_tables

Returns a list of all tables in the connected database.

describe_table

Provides the structure of a specified table, including columns and data types.