MySQL
Provides access to MySQL databases with fine-grained access control, supporting multiple databases simultaneously with configurable access modes (readonly, readwrite, full) and table-level permissions using whitelists, blacklists, wildcards, and rege
What is MySQL?
MySQL is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to provides access to mysql databases with fine-grained access control, supporting multiple databases simultaneously with configurable access modes (readonly, readwrite, full) and table-level permissions...
Provides access to MySQL databases with fine-grained access control, supporting multiple databases simultaneously with configurable access modes (readonly, readwrite, full) and table-level permissions using whitelists, blacklists, wildcards, and rege
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- Provides access to MySQL databases with fine-grained access
Use Cases
Maintainer
Works with
Installation
Manual Installation
npx mcp-server-for-mysqlConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use MySQL
MCP Server for MySQL gives AI assistants secure, fine-grained access to MySQL databases by exposing a `mysql_query` tool with configurable access controls and safety guardrails. It supports multiple simultaneous database connections, read-only mode by default (with explicit opt-in for INSERT, UPDATE, DELETE, and DDL), query rate limiting, SSL/TLS encryption, schema-level permission granularity using whitelists and blacklists, and SQL injection prevention through prepared statements. Database administrators and developers use it to let Claude query production or development databases without granting unrestricted access.
Prerequisites
- Node.js 18+ installed
- A running MySQL server (local or remote) with valid credentials
- The database user should have the minimum required privileges for the intended access mode
- An MCP-compatible client such as Claude Desktop or Claude Code
Install the package globally
Install the MCP server package from npm. The package name on npm is @benborla29/mcp-server-mysql.
npm install -g @benborla29/mcp-server-mysqlAdd to Claude Code
Use the claude mcp add command to register the server and pass your database credentials as environment variables.
claude mcp add mcp_server_mysql \
-e MYSQL_HOST="127.0.0.1" \
-e MYSQL_PORT="3306" \
-e MYSQL_USER="your_db_user" \
-e MYSQL_PASS="your_db_password" \
-e MYSQL_DB="your_database" \
-- npx @benborla29/mcp-server-mysqlConfigure Claude Desktop
Add the server block to your Claude Desktop configuration file with the required connection environment variables.
{
"mcpServers": {
"mcp_server_mysql": {
"command": "npx",
"args": ["-y", "@benborla29/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_db_user",
"MYSQL_PASS": "your_db_password",
"MYSQL_DB": "your_database"
}
}
}
}Enable write operations (optional)
By default only SELECT queries are allowed. To permit INSERT, UPDATE, or DELETE, explicitly set the corresponding environment variables to 'true'.
# Add these env vars to your config to enable write access:
ALLOW_INSERT_OPERATION=true
ALLOW_UPDATE_OPERATION=true
ALLOW_DELETE_OPERATION=false
ALLOW_DDL_OPERATION=falseVerify the connection
Restart your MCP client and ask Claude to list the tables in your database. If connected correctly, it will query the information_schema and return results.
MySQL Examples
Client configuration
Claude Desktop config with read-only access to a local MySQL database. Write operations remain disabled by default.
{
"mcpServers": {
"mcp_server_mysql": {
"command": "npx",
"args": ["-y", "@benborla29/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "readonly_user",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "your_database",
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false",
"MYSQL_RATE_LIMIT": "100"
}
}
}
}Prompts to try
Example prompts that use the mysql_query tool to explore schema, query data, and analyze database structure.
- "List all tables in the database and describe their columns"
- "Show me the 10 most recent orders from the orders table"
- "How many users signed up in the last 30 days?"
- "What are the foreign key relationships between the users and orders tables?"
- "Find all customers who have placed more than 5 orders"Troubleshooting MySQL
Connection refused or ECONNREFUSED error
Verify MYSQL_HOST and MYSQL_PORT are correct and that the MySQL server is running. For Docker-based MySQL, use the container's actual IP or host.docker.internal instead of 127.0.0.1.
Access denied for user error from MySQL
Check that MYSQL_USER and MYSQL_PASS are correct and that the user has been granted appropriate privileges on MYSQL_DB. Run `GRANT SELECT ON your_database.* TO 'your_user'@'%';` in MySQL if needed.
Write queries fail even after setting ALLOW_INSERT_OPERATION=true
Ensure the env variable is the string 'true' not a boolean. Also verify the MySQL user account has INSERT/UPDATE/DELETE privileges on the target tables — the server respects both server-side controls and database-level permissions.
Frequently Asked Questions about MySQL
What is MySQL?
MySQL is a Model Context Protocol (MCP) server that provides access to mysql databases with fine-grained access control, supporting multiple databases simultaneously with configurable access modes (readonly, readwrite, full) and table-level permissions using whitelists, blacklists, wildcards, and rege It connects AI assistants to external tools and data sources through a standardized interface.
How do I install MySQL?
Follow the installation instructions on the MySQL GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.
Which AI clients work with MySQL?
MySQL works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is MySQL free to use?
Yes, MySQL is open source and available under the MIT License license. You can use it freely in both personal and commercial projects.
MySQL Alternatives — Similar Databases Servers
Looking for alternatives to MySQL? Here are other popular databases servers you can use with Claude, Cursor, and VS Code.
Excelize
★ 20.6kGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
MCP Toolbox for Databases
★ 15.3kOpen source MCP server specializing in easy, fast, and secure tools for Databases.
DBHub
★ 2.8kA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.
Tabularis
★ 2.1kA lightweight, cross-platform database client for developers. Supports MySQL, PostgreSQL and SQLite. Hackable with plugins. Built for speed, security, and aesthetics.
Postgres AI Guide
★ 1.7kMCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
Anyquery
★ 1.7k🏎️ 🏠 ☁️ - Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by design.
Browse More Databases MCP Servers
Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up MySQL in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use MySQL?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.