# MySQL (read-only, switchable) [Health: Active]

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

## Description
Read-only MySQL access, with the database and server switchable mid-conversation.

## Tools
Capabilities this server exposes over MCP:

- **current_connection** — Show which MySQL server and database the read-only tools are currently pointed at
- **list_connections** — List the connection profiles available to switch to, including any added during this session
- **list_databases** — List databases on the currently connected MySQL server
- **use_database** — Switch the active database on the current MySQL server. Takes effect immediately, no restart needed
- **use_connection** — Switch to a named connection profile. Takes effect immediately, no restart needed
- **connect** — Connect to any MySQL server at runtime with explicit credentials. Not persisted to disk, but kept for the rest of the session under an alias
- **list_tables** — List all tables in the active database
- **describe_table** — Show columns and schema for a specific table
- **get_table_indexes** — Show indexes for a specific table
- **get_foreign_keys** — Show foreign key relationships for a specific table
- **get_table_sample** — Get sample rows from a table
- **run_query** — Execute a read-only SQL query (SELECT, WITH, SHOW, DESCRIBE, EXPLAIN only) against the active connection

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

```json
"mcpServers": {
  "mysql-read-only-switchable": {
    "command": "npx",
    "args": ["-y","@shibbirweb/mcp-mysql-read-only"],
    "env": {
      "MYSQL_HOST": "",
      "MYSQL_USER": "",
      "MYSQL_PASSWORD": "",
      "MYSQL_DATABASE": "",
      "MYSQL_PROFILES": "",
      "MYSQL_DEFAULT_PROFILE": ""
    }
  }
}
```

**Requires environment variables:** `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE`, `MYSQL_PROFILES`, `MYSQL_DEFAULT_PROFILE` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What the MySQL (read-only, switchable) MCP server does

The MySQL (read-only, switchable) MCP server exposes MySQL inspection and query operations to an MCP-compatible AI assistant. It can report the active server and database, show configured connection profiles, enumerate databases and tables, inspect columns, indexes, and foreign keys, return up to 50 sample rows, and execute one read-only statement.

The server is designed for sessions that move between targets. An assistant can change schemas on the current server, select a named profile, or open another server with explicit credentials. These operations do not require restarting the MCP client. The read-only behavior applies to the available database-reading tools and query execution.

## How it works

The process maintains the active connection as runtime state for the duration of the session. Configured targets are represented as named profiles, while the `connect` tool can open an additional target under an optional alias. Connection switches are checked with `SELECT 1` before becoming active; if verification fails, the previous connection remains selected.

Connections are pooled per target, so returning to a previously used target can reuse its existing pool. Reading tools can also receive an optional database for a single call without changing the active connection. This supports comparisons between databases without repeated permanent switches.

## Setup and configuration

The server runs through npm with `npx` or as a Docker container. The npm option requires Node 22 or newer. A basic setup supplies `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, and `MYSQL_DATABASE`. Docker users can use `host.docker.internal` to reach a MySQL service running on the host; `localhost` inside the container refers to the container itself.

Named profiles are supplied in `MYSQL_PROFILES` as a JSON object. Each profile requires a user and database; host defaults to `host.docker.internal`, port defaults to `3306`, and password defaults to an empty value. `MYSQL_DEFAULT_PROFILE` can select the initial profile. Invalid profiles missing required fields are skipped with a warning.

Claude Desktop uses an `mcpServers` entry in `claude_desktop_config.json`, and Claude Code uses the same structure in a project-level `.mcp.json`. Credentials in these files are stored as plain text, so the README recommends using a MySQL account limited to `SELECT` grants and keeping configuration files out of version control.

## Tools and capabilities

Connection tools include `current_connection`, `list_connections`, `list_databases`, `use_database`, `use_connection`, and `connect`. They show or change the active target without requiring a client restart.

Database-reading tools include `list_tables`, `describe_table`, `get_table_indexes`, `get_foreign_keys`, `get_table_sample`, and `run_query`. The last tool accepts one read-only statement. The MySQL (read-only, switchable) MCP server therefore fits schema exploration, data inspection, and read-only analysis rather than write workflows.

## Limitations and notes

This server does not provide write operations. Runtime connections opened with `connect` remain available for the current session but are not added permanently to `MYSQL_PROFILES`; adding a permanent profile requires configuration and a restart. Docker networking also changes how local addresses resolve, so a host MySQL instance should not be addressed as `localhost` from inside the container.

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

