home / mcp / mariadb / mysql database access mcp server

MariaDB / MySQL Database Access MCP Server

MCP Server for MariaDB

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "bretoreta-mariadb-mcp-server": {
      "command": "node",
      "args": [
        "/path/to/mariadb-mcp-server/dist/index.js"
      ],
      "env": {
        "MARIADB_HOST": "your-host",
        "MARIADB_PORT": "3306",
        "MARIADB_USER": "your-user",
        "MARIADB_DATABASE": "your-default-database",
        "MARIADB_PASSWORD": "your-password",
        "MARIADB_ROW_LIMIT": "1000",
        "MARIADB_TIMEOUT_MS": "10000",
        "MARIADB_ALLOW_DELETE": "false",
        "MARIADB_ALLOW_INSERT": "false",
        "MARIADB_ALLOW_UPDATE": "false"
      }
    }
  }
}

This MCP server gives you read-only access to MariaDB and MySQL databases, enabling you to list databases and tables, inspect table schemas, and run safe queries with built-in protections against modification attempts.

How to use

Connect to the MariaDB / MySQL MCP server using your MCP client. You can perform the following actions: list available databases, list tables in a database, describe a table’s schema, and execute read-only SQL queries. The server enforces read-only access by default and validates queries to prevent SQL injection and unintended data modifications. If you need to review result sizes or prevent long-running work, you can rely on the row limit and query timeout protections.

How to install

Prerequisites: install Node.js (LTS version) and a package manager. This server uses a standard Node runtime and is built from source.

# Clone the MCP server repository
git clone https://github.com/bretoreta/mariadb-mcp-server.git
cd mariadb-mcp-server

# Install dependencies and build
pnpm install
pnpm run build

Configuration and running

Prepare the required environment variables to connect to your MariaDB / MySQL instance. Provide these values in the environment when starting the MCP server.

{
  "mcpServers": {
    "mariadb": {
      "command": "node",
      "args": ["/path/to/mariadb-mcp-server/dist/index.js"],
      "env": {
        "MARIADB_HOST": "your-host",
        "MARIADB_PORT": "3306",
        "MARIADB_USER": "your-user",
        "MARIADB_PASSWORD": "your-password",
        "MARIADB_DATABASE": "your-default-database",
        "MARIADB_ALLOW_INSERT": "false",
        "MARIADB_ALLOW_UPDATE": "false",
        "MARIADB_ALLOW_DELETE": "false",
        "MARIADB_TIMEOUT_MS": "10000",
        "MARIADB_ROW_LIMIT": "1000"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Security and safety features

Read-only access is the default, allowing only SELECT, SHOW, DESCRIBE, and EXPLAIN operations. Queries undergo validation to help prevent SQL injection and any data modification attempts are blocked. A query timeout prevents long-running queries from consuming resources, and a row limit controls the amount of data returned in a single response.

Notes on usage

When you configure access, ensure your user has the appropriate permissions for the intended read-only operations. Use the provided environment variables to connect to the database, and respect the default database when none is specified in a request.

Available tools

list_databases

Lists all accessible databases on the MariaDB / MySQL server.

list_tables

Lists all tables in a specified database, using the default database if none is provided.

describe_table

Shows the schema for a specific table, including column types and constraints.

execute_query

Executes a SQL query with optional database context, returning results for read-only statements.