MySQL MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "MYSQL_HOST=${MYSQL_HOST}" -e "MYSQL_PORT=${MYSQL_PORT}" -e "MYSQL_USER=${MYSQL_USER}" -e "MYSQL_PASSWORD=${MYSQL_PASSWORD}" -e "MYSQL_DATABASE=${MYSQL_DATABASE}" mysql-mcp-server -- npx @lakshya-mcp/mysql-mcp-server-claude
Required:MYSQL_HOSTMYSQL_PORTMYSQL_USERMYSQL_PASSWORDMYSQL_DATABASE+ 1 optional
README.md

A secure, feature-rich MySQL Model Context Protocol server

MySQL MCP Server

A secure, feature-rich MySQL Model Context Protocol (MCP) server designed for integration with AI assistants like Claude and VS Code GitHub Copilot.

Features

  • Security First: Built with security best practices, input validation, and configurable access controls
  • Configurable Operations: Enable/disable CRUD operations and table creation based on your needs (read operations enabled by default)
  • Tabular Data Display: Properly formatted responses for easy data visualization
  • Comprehensive Logging: Detailed logging for debugging and monitoring
  • Environment-Based Configuration: Easy setup using environment variables or configuration objects
  • NPM Package: Ready to use as a dependency in your projects

Usage

With Visual Studio Code

Add this to your .vscode/mcp.json:

{
  "servers": {
    "mysql": {
      "command": "npx",
      "args": ["@lakshya-mcp/mysql-mcp-server-claude"],
      "env": {
        "MYSQL_HOST": "{your_host}",
        "MYSQL_PORT": "{your_port}",
        "MYSQL_USER": "{your_username}",
        "MYSQL_PASSWORD": "{your_password}",
        "MYSQL_DATABASE": "{your_database}",
        "MYSQL_ALLOW_CREATE": "false",
        "MYSQL_ALLOW_UPDATE": "false",
        "MYSQL_ALLOW_DELETE": "false",
        "MYSQL_ALLOW_CREATE_TABLE": "false",
        "MYSQL_READ_ONLY": "true" // Set to "true" for read-only mode; "false" allows writes.
      }
    }
  }
}

With Claude Desktop

Add this to your claude_desktop_config.json. Follow these instructions to locate file.

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@lakshya-mcp/mysql-mcp-server-claude"],
      "env": {
        "MYSQL_HOST": "{your_host}",
        "MYSQL_PORT": "{your_port}",
        "MYSQL_USER": "{your_username}",
        "MYSQL_PASSWORD": "{your_password}",
        "MYSQL_DATABASE": "{your_database}",
        "MYSQL_ALLOW_CREATE": "false",
        "MYSQL_ALLOW_UPDATE": "false",
        "MYSQL_ALLOW_DELETE": "false",
        "MYSQL_ALLOW_CREATE_TABLE": "false",
        "MYSQL_READ_ONLY": "true" // Set to "true" for read-only mode; "false" allows writes.
      }
    }
  }
}

Save file and restart claude desktop. It should be visible under tools (check icon next to +).

With Claude Code

Open terminal and run this command:

For windows (without wsl):

claude mcp add mysql -e MYSQL_HOST=localhost -e MYSQL_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASSWORD={your_password} -e MYSQL_DATABASE={your_database} -e MYSQL_ALLOW_CREATE=false -e MYSQL_ALLOW_UPDATE=false -e MYSQL_ALLOW_DELETE=false -e MYSQL_ALLOW_CREATE_TABLE=false -e MYSQL_READ_ONLY=true -- cmd /c npx @lakshya-mcp/mysql-mcp-server-claude

For mac / windows (with wsl):

claude mcp add mysql -e MYSQL_HOST=localhost -e MYSQL_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASSWORD={your_password} -e MYSQL_DATABASE={your_database} -e MYSQL_ALLOW_CREATE=false -e MYSQL_ALLOW_UPDATE=false -e MYSQL_ALLOW_DELETE=false -e MYSQL_ALLOW_CREATE_TABLE=false -e MYSQL_READ_ONLY=true -- npx -y @lakshya-mcp/mysql-mcp-server-claude

Then type: claude and run /mcp. It should show:

 ❯ 1. mysql  ✔ connected · Enter to view details

With Gemini CLI

Navigate to your home directory and look for a folder named .gemini. Inside that folder, you will find the settings.json file. Add this in your .gemini/settings.json file:

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@lakshya-mcp/mysql-mcp-server-claude"],
      "env": {
        "MYSQL_HOST": "{your_host}",
        "MYSQL_PORT": "{your_port}",
        "MYSQL_USER": "{your_username}",
        "MYSQL_PASSWORD": "{your_password}",
        "MYSQL_DATABASE": "{your_database}",
        "MYSQL_ALLOW_CREATE": "false",
        "MYSQL_ALLOW_UPDATE": "false",
        "MYSQL_ALLOW_DELETE": "false",
        "MYSQL_ALLOW_CREATE_TABLE": "false",
        "MYSQL_READ_ONLY": "true" // Set to "true" for read-only mode; "false" allows writes.
      }
    }
  }
}

Then restart gemini cli. You should be able to see mysql mcp server. You can verify by running /mcp.

Within your project

Tools (3)

list_tablesLists all tables in the connected MySQL database
describe_tableRetrieves the schema structure of a specific table
queryExecutes a SQL query against the database

Environment Variables

MYSQL_HOSTrequiredThe hostname of the MySQL server
MYSQL_PORTrequiredThe port number of the MySQL server
MYSQL_USERrequiredThe username for database authentication
MYSQL_PASSWORDrequiredThe password for database authentication
MYSQL_DATABASErequiredThe name of the database to connect to
MYSQL_READ_ONLYSet to true to restrict operations to read-only mode

Configuration

claude_desktop_config.json
{"mcpServers": {"mysql": {"command": "npx", "args": ["@lakshya-mcp/mysql-mcp-server-claude"], "env": {"MYSQL_HOST": "{your_host}", "MYSQL_PORT": "{your_port}", "MYSQL_USER": "{your_username}", "MYSQL_PASSWORD": "{your_password}", "MYSQL_DATABASE": "{your_database}", "MYSQL_READ_ONLY": "true"}}}}

Try it

List all the tables available in my current MySQL database.
Describe the schema of the 'users' table so I can understand its columns.
Write a SQL query to find all users who signed up in the last 30 days.
Show me the first 10 rows of the 'orders' table.

Frequently Asked Questions

What are the key features of MySQL MCP Server?

Secure input validation and configurable access controls. Enable or disable CRUD operations and table creation. Properly formatted tabular data display for AI visualization. Comprehensive logging for debugging and monitoring. Environment-based configuration for easy setup.

What can I use MySQL MCP Server for?

Allowing AI assistants to perform ad-hoc data analysis on production databases safely. Automating schema documentation by having the AI describe table structures. Enabling non-technical users to query database information using natural language. Integrating database management directly into the VS Code development workflow.

How do I install MySQL MCP Server?

Install MySQL MCP Server by running: npx @lakshya-mcp/mysql-mcp-server-claude

What MCP clients work with MySQL MCP Server?

MySQL MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep MySQL MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare