# read-only-local-mysql-mcp-server [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/hovecapital/read-only-local-mysql-mcp-server  
**GitHub Stars:** 8  
**npm Downloads (last month):** 818  
**Views:** 12  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/read-only-local-mysql-mcp-server

## Description
MCP server enabling read-only MySQL queries for Claude Desktop

## Tools
Capabilities this server exposes over MCP:

- **connect** — Connect to a MySQL database using a connection string. The connection will be used for subsequent queries until changed.
- **disconnect** — Disconnect from the current runtime database and revert to the default environment-configured connection
- **query** — Run a read-only SQL query against the currently connected database

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `npx` (confidence: high):

```json
"mcpServers": {
  "read-only-local-mysql-mcp-server": {
    "command": "npx",
    "args": ["-y","@hovecapital/read-only-mysql-mcp-server@latest"],
    "env": {
      "DB_HOST": "",
      "DB_PORT": "",
      "DB_DATABASE": "",
      "DB_USERNAME": "",
      "DB_PASSWORD": "",
      "DB_ALLOWED_HOSTS": ""
    }
  }
}
```

**Requires environment variables:** `DB_HOST`, `DB_PORT`, `DB_DATABASE`, `DB_USERNAME`, `DB_PASSWORD`, `DB_ALLOWED_HOSTS` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What read-only-local-mysql-mcp-server MCP server does

The read-only-local-mysql-mcp-server MCP server lets an MCP-compatible client work with MySQL through natural-language requests that the client turns into SQL. It is intended for inspecting database structure and reading records, not for modifying data.

The server exposes three tools: `connect` selects a runtime database from a MySQL connection string, `disconnect` ends that runtime selection and returns to the environment-configured database, and `query` executes a read-only SQL statement. Query results are returned in JSON format.

Typical requests include listing tables, inspecting a table definition, retrieving a limited set of rows, counting records, and filtering results.

## How it works

At startup, the server reads the default database connection from environment variables. A call to `connect` changes the active connection for later queries until `disconnect` is called. The `query` tool can also receive a connection string for a single request, which takes precedence over the persistent runtime connection and the environment-based default.

The read-only-local-mysql-mcp-server MCP server accepts a MySQL URL in the form `mysql://username:password@hostname:port/database_name`. Host access is restricted: the configured `DB_HOST` and loopback addresses are allowed, and additional destinations can be supplied through `DB_ALLOWED_HOSTS`.

Before execution, SQL is validated. Supported statement forms are `SELECT`, `WITH`, `SHOW`, `DESCRIBE`, and `EXPLAIN`. The validation permits one statement and rejects comments. Queries also run in a server-side read-only transaction, providing an additional safeguard against changes.

## Setup and configuration

Node.js 16 or newer, a reachable MySQL server, and an MCP client are listed as prerequisites. The package can be launched with `npx`, installed globally from npm, or built locally after cloning the repository with `npm install` and `npm run build`.

For the default connection, configure these variables in the MCP client definition:

- `DB_HOST`: MySQL hostname
- `DB_PORT`: MySQL port
- `DB_DATABASE`: database name
- `DB_USERNAME`: MySQL user
- `DB_PASSWORD`: password
- `DB_ALLOWED_HOSTS`: optional comma-separated additional hosts permitted in connection strings

The documented `npx` command uses `@hovecapital/read-only-mysql-mcp-server@latest`. Claude Code can add it through the `claude mcp add` command, while Claude Desktop uses its MCP configuration file. After changing configuration, restart the client.

## Tools and capabilities

- `connect(connectionString)`: establishes a persistent runtime connection.
- `disconnect()`: closes the runtime connection and restores the environment-configured default.
- `query(sql, connectionString?)`: executes a read-only query, optionally using a connection string only for that request.
- JSON-formatted query output.
- Runtime database switching without restarting the server.
- Validation for permitted read-only SQL statement types.

## Limitations and notes

The read-only-local-mysql-mcp-server MCP server does not provide write operations. SQL outside the supported statement types, multiple statements, or statements containing comments are rejected. Host restrictions also prevent arbitrary connection targets unless they are the configured host, loopback, or listed in `DB_ALLOWED_HOSTS`.

Credentials are supplied through environment variables or connection strings, so deployment should account for how the MCP client stores and passes those values.

_Full upstream README: https://allmcps.com/mcp/read-only-local-mysql-mcp-server/readme_

