Home / MCP / MySQL MCP Server

MySQL MCP Server

Provides an MCP server that executes SQL queries against a MySQL database and returns results in JSON.

javascript
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "mysql_mcp": {
            "command": "node",
            "args": [
                "/path/to/mysql-mcp-server/build/index.js"
            ],
            "env": {
                "MYSQL_HOST": "localhost",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "mcp101",
                "MYSQL_PASSWORD": "123qwe",
                "MYSQL_DATABASE": "mcpdb"
            }
        }
    }
}

You can run a MySQL MCP Server locally to execute SQL queries against a MySQL database and receive results in JSON. It enables read and write operations while keeping actions auditable through transaction logging, making it convenient to integrate SQL data access into your conversations or automated workflows.

How to use

You interact with the MySQL MCP Server from an MCP client. Start the local server as configured, then issue SQL commands through supported tools to run queries, create tables, insert data, update records, or delete data. The server executes your SQL statements on the configured MySQL database and returns results in JSON format for easy consumption in your application or chat workflow.

How to install

Prerequisites you need before installation:

  • Node.js (v14 or higher)
  • MySQL server
  • MCP SDK

Install and build the MCP server with these commands:

# 1) Clone or download the project
# 2) Install dependencies
cd mysql-mcp-server
npm install

# 3) Build the server
npm run build

Additional configuration and usage notes

Configure the server by setting environment variables for the MySQL connection. The following variables are used by the MCP server to connect to the MySQL database. You can place these in your environment or in your MCP launcher configuration.

{
  "mcpServers": {
    "mysql_mcp": {
      "type": "stdio",
      "name": "mysql_mcp",
      "command": "node",
      "args": ["/path/to/mysql-mcp-server/build/index.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "mcp101",
        "MYSQL_PASSWORD": "123qwe",
        "MYSQL_DATABASE": "mcpdb"
      }
    }
  }
}

Examples of available operations

The server exposes a set of operations to interact with your MySQL database. You can perform read operations, create tables, insert data, update existing records, and delete rows. Results from queries are returned in JSON format for easy parsing in your client.

{
  "tool": "run_sql_query",
  "query": "SELECT * FROM test_users"
}

Available tools

run_sql_query

Executes a read-only SQL SELECT query against the MySQL database and returns results in JSON.

create_table

Executes a SQL CREATE TABLE query to define new tables in the database.

insert_data

Executes a SQL INSERT INTO query to add new rows to a table.

update_data

Executes a SQL UPDATE query to modify existing rows in a table.

delete_data

Executes a SQL DELETE FROM query to remove rows from a table.