# mcp-server-mysql

> MCP Server

This repository provides a Model Context Protocol (MCP) server for read-only access to MySQL databases, enabling LLMs to inspect schemas and execute secure, parameterized queries with configurable timeouts and pagination.

## Overview

- **Category:** Database
- **Language:** TypeScript
- **Stars:** 2042
- **Forks:** 18
- **Owner:** benborla
- **GitHub:** https://github.com/benborla/mcp-server-mysql
- **Created:** 2024-12-09T14:02:55+00:00
- **Updated:** 2025-03-28T21:47:39+00:00
- **Source:** https://model-context-protocol.com/servers/mcp-server-mysql-llm-read-only

## Setup

## Setup

**Using Smithery:**
Install using Smithery with `npx -y @smithery/cli@latest install @benborla29/mcp-server-mysql --client claude` and follow the prompts.

**Using MCP Get:**
Install using MCP Get with `npx @michaellatman/mcp-get@latest install @benborla29/mcp-server-mysql`.

**Using NPM/PNPM:**
Install globally using `npm install -g @benborla29/mcp-server-mysql` or `pnpm add -g @benborla29/mcp-server-mysql`.

**Manual Configuration for Claude Desktop App:**
Add the MCP server configuration to your `claude_desktop_config.json` file, including command, arguments, and environment variables for MySQL connection.

**Advanced Configuration Options:**
Customize the MCP server's behavior by modifying the `mcpServers` configuration in your `claude_desktop_config.json` file, adjusting environment variables for performance, security, and monitoring.

**Testing Database Setup:**
1. Create a test database and user in MySQL.
2. Run the database setup script using `pnpm run setup:test:db`.
3. Configure the test environment by creating a `.env.test` file with MySQL connection details.
4. Add scripts to your `package.json` for database setup and testing.

**Running Tests:**
Run tests using `pnpm test` after setting up the test database.

## Tools

## Available Tools

1.  **mysql_query** (Execute read-only SQL queries against the connected database.)
2.  **Table Schemas** (Provides JSON schema information for each table, including column names, data types, index information, constraints, and foreign key relationships.)
3.  **SQL injection prevention** (Prevents SQL injection through prepared statements.)
4.  **Query whitelisting/blacklisting capabilities** (Provides query whitelisting/blacklisting capabilities.)
5.  **Rate limiting** (Implements rate limiting for query execution.)
6.  **Optimized connection pooling** (Offers optimized connection pooling.)
7.  **Query result caching** (Supports query result caching.)
8.  **Comprehensive query logging** (Provides comprehensive query logging.)
