The MCP Server for MySQL allows Large Language Models (LLMs) to interact with MySQL databases, providing capabilities to inspect database schemas and execute SQL queries. It serves as a bridge between LLMs and your MySQL database through the Model Context Protocol.
If you already have the MCP server configured in Claude Desktop:
claude mcp add-from-claude-desktop
This will display an interactive dialog where you can select the mcp_server_mysql
server to import with all existing configuration.
First, install the package globally:
# Using npm
npm install -g @benborla29/mcp-server-mysql
# Using pnpm
pnpm add -g @benborla29/mcp-server-mysql
Then add the server to Claude Code:
claude mcp add mcp_server_mysql \
-e MYSQL_HOST="127.0.0.1" \
-e MYSQL_PORT="3306" \
-e MYSQL_USER="root" \
-e MYSQL_PASS="your_password" \
-e MYSQL_DB="your_database" \
-e ALLOW_INSERT_OPERATION="false" \
-e ALLOW_UPDATE_OPERATION="false" \
-e ALLOW_DELETE_OPERATION="false" \
-- npx @benborla29/mcp-server-mysql
For local MySQL instances using Unix sockets:
claude mcp add mcp_server_mysql \
-e MYSQL_SOCKET_PATH="/tmp/mysql.sock" \
-e MYSQL_USER="root" \
-e MYSQL_PASS="your_password" \
-e MYSQL_DB="your_database" \
-e ALLOW_INSERT_OPERATION="false" \
-e ALLOW_UPDATE_OPERATION="false" \
-e ALLOW_DELETE_OPERATION="false" \
-- npx @benborla29/mcp-server-mysql
# Local scope (default) - only available in current project
claude mcp add mcp_server_mysql [options...]
# User scope - available across all your projects
claude mcp add mcp_server_mysql -s user [options...]
# Project scope - shared with team members via .mcp.json
claude mcp add mcp_server_mysql -s project [options...]
For database servers with credentials, local or user scope is recommended to keep credentials private.
After adding the server, verify it's configured correctly:
# List all configured servers
claude mcp list
# Get details for your MySQL server
claude mcp get mcp_server_mysql
# Check server status within Claude Code
/mcp
To run in remote mode:
Create an env file in your preferred directory:
touch .env
Configure your environment variables, setting:
IS_REMOTE_MCP=true
REMOTE_SECRET_KEY
to a secure stringPORT
if needed (default is 3000)Load variables in the current session:
source .env
Run the server:
npx @benborla29/mcp-server-mysql
Configure your agent to connect to the MCP with this configuration:
{
"mcpServers": {
"mysql": {
"url": "http://your-host:3000/mcp",
"type": "streamableHttp",
"headers": {
"Authorization": "Bearer <REMOTE_SECRET_KEY>"
}
}
}
}
ALLOW_INSERT_OPERATION=true
)ALLOW_UPDATE_OPERATION=true
)ALLOW_DELETE_OPERATION=true
)The server provides comprehensive database information:
MYSQL_SOCKET_PATH
: Unix socket path for local connectionsMYSQL_HOST
: MySQL server host (default: "127.0.0.1")MYSQL_PORT
: MySQL server port (default: "3306")MYSQL_USER
: MySQL username (default: "root")MYSQL_PASS
: MySQL passwordMYSQL_DB
: Target database name (leave empty for multi-DB mode)MYSQL_POOL_SIZE
: Connection pool size (default: "10")MYSQL_QUERY_TIMEOUT
: Query timeout in milliseconds (default: "30000")MYSQL_CACHE_TTL
: Cache time-to-live in milliseconds (default: "60000")MYSQL_RATE_LIMIT
: Maximum queries per minute (default: "100")MYSQL_MAX_QUERY_COMPLEXITY
: Maximum query complexity score (default: "1000")MYSQL_SSL
: Enable SSL/TLS encryption (default: "false")ALLOW_INSERT_OPERATION
: Enable INSERT operations (default: "false")ALLOW_UPDATE_OPERATION
: Enable UPDATE operations (default: "false")ALLOW_DELETE_OPERATION
: Enable DELETE operations (default: "false")ALLOW_DDL_OPERATION
: Enable DDL operations (default: "false")For more control over the MCP server's behavior:
{
"mcpServers": {
"mcp_server_mysql": {
"command": "/path/to/npx/binary/npx",
"args": [
"-y",
"@benborla29/mcp-server-mysql"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "",
"MYSQL_DB": "db_name",
"PATH": "/path/to/node/bin:/usr/bin:/bin",
"MYSQL_POOL_SIZE": "10",
"MYSQL_QUERY_TIMEOUT": "30000",
"MYSQL_CACHE_TTL": "60000",
"MYSQL_RATE_LIMIT": "100",
"MYSQL_MAX_QUERY_COMPLEXITY": "1000",
"MYSQL_SSL": "true",
"ENABLE_LOGGING": "true",
"MYSQL_LOG_LEVEL": "info",
"MYSQL_METRICS_ENABLED": "true",
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false"
}
}
}
}
MCP-Server-MySQL supports connecting to multiple databases when no specific database is set. This allows the LLM to query any database the MySQL user has access to.
To enable multi-DB mode, simply leave the MYSQL_DB
environment variable empty. In multi-DB mode, queries require schema qualification:
-- Use fully qualified table names
SELECT * FROM database_name.table_name;
-- Or use USE statements to switch between databases
USE database_name;
SELECT * FROM table_name;
For multi-database configuration with Claude Code:
claude mcp add mcp_server_mysql_multi \
-e MYSQL_HOST="127.0.0.1" \
-e MYSQL_PORT="3306" \
-e MYSQL_USER="root" \
-e MYSQL_PASS="your_password" \
-e MULTI_DB_WRITE_MODE="false" \
-- npx @benborla29/mcp-server-mysql
For fine-grained control over database operations, you can configure schema-specific permissions:
SCHEMA_INSERT_PERMISSIONS=development:true,test:true,production:false
SCHEMA_UPDATE_PERMISSIONS=development:true,test:true,production:false
SCHEMA_DELETE_PERMISSIONS=development:false,test:true,production:false
SCHEMA_DDL_PERMISSIONS=development:false,test:true,production:false
Connection Issues
Path Resolution If you encounter an error "Could not connect to MCP server mcp-server-mysql", explicitly set the path of all required binaries:
{
"env": {
"PATH": "/path/to/node/bin:/usr/bin:/bin"
}
}
Find your Node.js paths with:
# For PATH environment variable
echo "$(which node)/../"
# For NODE_PATH environment variable
echo "$(which node)/../../lib/node_modules"
Authentication Issues
caching_sha2_password
authentication pluginModule Not Found Error
If encountering Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'dotenv'
, try:
npx -y -p @benborla29/mcp-server-mysql -p dotenv mcp-server-mysql
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mcp_server_mysql" '{"command":"npx","args":["-y","@benborla29/mcp-server-mysql"],"env":{"MYSQL_HOST":"127.0.0.1","MYSQL_PORT":"3306","MYSQL_USER":"root","MYSQL_PASS":"your_password","MYSQL_DB":"your_database","ALLOW_INSERT_OPERATION":"false","ALLOW_UPDATE_OPERATION":"false","ALLOW_DELETE_OPERATION":"false"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mcp_server_mysql": {
"command": "npx",
"args": [
"-y",
"@benborla29/mcp-server-mysql"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "your_database",
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mcp_server_mysql": {
"command": "npx",
"args": [
"-y",
"@benborla29/mcp-server-mysql"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "your_database",
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect