# database-mcp-mysql

Connects AI assistants to MySQL instances with read-only safeguards. Useful for exploring schemas and inspecting data without write hazards.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 5
- Author: arifulislamat
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/arifulislamat/database-mcp
- Updated: 2026-10-18
- HTML: https://affpapa.org/en/nevibecode/mcp/database-mcp-mysql

## What it does

The server provides two tools for AI models: `search_objects` and `execute_sql`. Running the schema inspector without arguments outputs table names. Supplying a table name reveals its column types, indexes, and foreign keys. The second tool runs the queries.

Safeguards protect against database mutations on two fronts. The tool checks statements before execution and sets a read-only session inside MySQL. Default limits restrict output to 1000 rows and stop commands after 30 seconds.

Database credentials cannot be passed inside chat prompts. The process reads configuration exclusively on startup from flags, a YAML document, or `MYSQL_*` environment variables.

## Requirements
- Needs: Node.js (commands run via npx)
- Environment variables: `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add database-mcp-mysql -e MYSQL_HOST=<MYSQL_HOST> -e MYSQL_USER=<MYSQL_USER> -e MYSQL_PASSWORD=<MYSQL_PASSWORD> -e MYSQL_DATABASE=<MYSQL_DATABASE> -- npx -y @database-mcp/mysql
```
Replace <…> with your own values

### Codex

**Platform CLI**
```bash
codex mcp add database-mcp-mysql --env MYSQL_HOST=<MYSQL_HOST> --env MYSQL_USER=<MYSQL_USER> --env MYSQL_PASSWORD=<MYSQL_PASSWORD> --env MYSQL_DATABASE=<MYSQL_DATABASE> -- npx -y @database-mcp/mysql
```
Replace <…> with your own values

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "database-mcp-mysql": {
            "command": "npx",
            "args": [
                "-y",
                "@database-mcp/mysql"
            ],
            "env": {
                "MYSQL_HOST": "<MYSQL_HOST>",
                "MYSQL_USER": "<MYSQL_USER>",
                "MYSQL_PASSWORD": "<MYSQL_PASSWORD>",
                "MYSQL_DATABASE": "<MYSQL_DATABASE>"
            }
        }
    }
}
```
Replace <…> with your own values

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "database-mcp-mysql": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "@database-mcp/mysql"
            ],
            "env": {
                "MYSQL_HOST": "<MYSQL_HOST>",
                "MYSQL_USER": "<MYSQL_USER>",
                "MYSQL_PASSWORD": "<MYSQL_PASSWORD>",
                "MYSQL_DATABASE": "<MYSQL_DATABASE>"
            }
        }
    }
}
```
Replace <…> with your own values

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e MYSQL_HOST=<MYSQL_HOST> -e MYSQL_USER=<MYSQL_USER> -e MYSQL_PASSWORD=<MYSQL_PASSWORD> -e MYSQL_DATABASE=<MYSQL_DATABASE> database-mcp-mysql npx -y @database-mcp/mysql
```
Replace <…> with your own values

## When to use it
- inspect MySQL tables, indexes, and foreign keys
- run analytical SQL queries without accidental writes
- cut off slow database statements with a 30-second timeout
- keep connection passwords out of application logs

## Example prompts
- Inspect the schema of the customers table and list its indexes.
- Find the five most recent entries in the orders table.
- List every table present in the current MySQL database.

## Similar
- [World Monitor](https://affpapa.org/en/nevibecode/mcp/world-monitor.md) — MCP server · ★ 89609
- [Scrapling MCP Server](https://affpapa.org/en/nevibecode/mcp/scrapling-mcp-server.md) — MCP server · ★ 89899
- [MCP Toolbox for Databases](https://affpapa.org/en/nevibecode/mcp/googleapis-mcp-toolbox-for-databases.md) — MCP server · ★ 16730
- [PostHog MCP Server](https://affpapa.org/en/nevibecode/mcp/posthog-mcp-server.md) — MCP server · ★ 40459
- [dbx](https://affpapa.org/en/nevibecode/mcp/dbx.md) — MCP server · ★ 27844
- [Metabase](https://affpapa.org/en/nevibecode/mcp/metabase.md) — MCP server · ★ 49863

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
