https://github.com/benborla/mcp-server-mysql
A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
https://github.com/benborla/mcp-server-mysql
Last synced: 5 months ago
JSON representation
A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
- Host: GitHub
- URL: https://github.com/benborla/mcp-server-mysql
- Owner: benborla
- License: mit
- Created: 2024-12-09T14:02:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-18T09:42:25.000Z (7 months ago)
- Last Synced: 2025-11-18T11:23:51.968Z (7 months ago)
- Language: JavaScript
- Size: 28.5 MB
- Stars: 918
- Watchers: 10
- Forks: 264
- Open Issues: 24
-
Metadata Files:
- Readme: README-MULTI-DB.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-mcp - benborla/mcp-server-mysql
- best-of-mcp-servers - GitHub - 49% open · ⏱️ 10.03.2026) (Databases)
- awesome-mcp-servers - MySQL - A Node.js-based MCP server for MySQL database access with access controls and inspection. (Community Servers)
- awesome-mcp-zh - benborla29/mcp-server-mysql
- awesome-mcp-servers - benborla29/mcp-server-mysql - یکپارچهسازی پایگاه داده MySQL در NodeJS با کنترلهای دسترسی قابل تنظیم و بازرسی schema (پیادهسازیهای سرور / 🗄️ <a name="databases"></a>پایگاههای داده)
- metorial-index - MySQL Server - Provides read-only access to MySQL databases, enabling inspection of database schemas and execution of read-only SQL queries. (APIs and HTTP Requests)
- awesome-mcp-servers - MySQL MCP
- toolsdk-mcp-registry - ❌ @benborla29/mcp-server-mysql - only MySQL database access to execute queries and analyze data patterns. (node) (Databases / How to Submit)
- awesome-mcp-security - mcp-server-mysql - only access to MySQL datab... | 90 ✅ | 1.3k | [表示](https://agentseal.org/mcp/benborla29-mcp-server-mysql) | (カテゴリ / 🗄️ <a name="database--sql"></a>データベース・SQL)
- awesome-mcp-servers - MySQL MCP Server (NodeJS, benborla) - A Node.js-based MySQL MCP server with configurable access controls and schema inspection, enabling secure LLM access to MySQL databases. ([Read more](/details/mysql-mcp-server-nodejs-benborla.md)) (Mcp Server Directories & Lists)
- awesome-mcp - MySQL MCP - MySQL database integration (Data & Databases / SQL Databases)
- awesome-mcp-lists - GitHub
- awesome-mcp-servers - **mcp-server-mysql** - A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries. `javascript` `server` `database` `llm` `mysql` `npm install benborla/mcp-server-mysql` (🌐 Web Development)
- awesome-mcp-servers - MySQL MCP Server - A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries. (Table of Contents / Databases)
- awesome-mcp-registry - benborla/mcp-server-mysql - only access to MySQL databases. | (Databases (4))
- awesome-openclaw-skills - benborla/mcp-server-mysql - only access to MySQL databases. This server enabl... | 1.4k | (MCP Servers & Protocol)
- awesome-offensive-mcp - **MySQL MCP**
- awesome-mcp - benborla/mcp-server-mysql - mcp-server-mysql is a Model Context Protocol server that provides secure, read-only access to MySQL databases, enabling large language models to inspect schemas and execute SQL queries efficiently. (MCP Servers / Databases)
README
# Multi-DB Mode and Schema-Specific Permissions
This document describes the new multi-database mode and schema-specific permissions features added to the MCP-Server-MySQL.
## Multi-DB Mode
MCP-Server-MySQL now supports working with multiple databases simultaneously when no specific database is set in the configuration.
### How to Enable Multi-DB Mode
To enable multi-DB mode, simply leave the `MYSQL_DB` environment variable empty:
```json
{
"mcpServers": {
"mcp_server_mysql": {
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "", // Empty to enable multi-DB mode
...
}
}
}
}
```
### Features in Multi-DB Mode
1. **List All Databases**: In multi-DB mode, the server will list resources from all available databases when the LLM requests database schemas.
2. **Query Any Database**: You can execute queries against any database to which the MySQL user has access.
3. **Schema Qualification Required**: When working in multi-DB mode, you should use fully qualified table names with schema/database prefixes:
```sql
-- 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;
```
4. **Automatic Read-Only Mode**: For safety, multi-DB mode enforces read-only operations by default. This can be customized using schema-specific permissions (see below).
5. **Database Exploration**: You can explore databases using commands like:
```sql
-- List all databases
SHOW DATABASES;
-- List tables in a specific database
SHOW TABLES FROM database_name;
-- Describe a table's structure
DESCRIBE database_name.table_name;
```
## Schema-Specific Permissions
This new feature allows fine-grained control over which operations are allowed on specific database schemas.
### Available Permission Types
1. **INSERT Permissions**: Control which schemas can have new records inserted.
2. **UPDATE Permissions**: Control which schemas can have records updated.
3. **DELETE Permissions**: Control which schemas can have records deleted.
4. **DDL Permissions**: Control which schemas can have their structure modified (CREATE, ALTER, DROP, TRUNCATE).
### How to Configure Schema-Specific Permissions
Set the following environment variables with a comma-separated list of schema:permission pairs:
```txt
SCHEMA_INSERT_PERMISSIONS=production:false,development:true,test:true
SCHEMA_UPDATE_PERMISSIONS=production:false,development:true,test:true
SCHEMA_DELETE_PERMISSIONS=production:false,development:false,test:true
SCHEMA_DDL_PERMISSIONS=production:false,development:false,test:true
```
This configuration:
- Allows INSERT and UPDATE on development and test databases, but not production
- Allows DELETE and DDL operations only on the test database
- Blocks all write operations on the production database
### Example Configuration
Here's a complete example configuration with schema-specific permissions:
```json
{
"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": "", // Empty for multi-DB mode
// Global defaults (apply when no schema-specific permission is set)
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false",
"ALLOW_DDL_OPERATION": "false",
// Schema-specific permissions
"SCHEMA_INSERT_PERMISSIONS": "dev_db:true,test_db:true,prod_db:false",
"SCHEMA_UPDATE_PERMISSIONS": "dev_db:true,test_db:true,prod_db:false",
"SCHEMA_DELETE_PERMISSIONS": "dev_db:false,test_db:true,prod_db:false",
"SCHEMA_DDL_PERMISSIONS": "dev_db:false,test_db:true,prod_db:false"
}
}
}
}
```
### Permission Resolution Logic
1. If a schema-specific permission is set, it takes precedence over the global setting.
2. If no schema-specific permission is found, the global setting (`ALLOW_X_OPERATION`) is used.
3. In multi-DB mode, if a query doesn't specify a schema and one can't be determined from context, only read operations are allowed for safety.
## Environment Variables Summary
### Multi-DB Mode
- `MYSQL_DB`: Leave empty to enable multi-DB mode
- `MULTI_DB_WRITE_MODE`: Set to "true" to allow write operations in multi-DB mode without schema-specific permissions (not recommended for security)
### Schema-Specific Permissions
- `SCHEMA_INSERT_PERMISSIONS`: Control INSERT permissions per schema
- `SCHEMA_UPDATE_PERMISSIONS`: Control UPDATE permissions per schema
- `SCHEMA_DELETE_PERMISSIONS`: Control DELETE permissions per schema
- `SCHEMA_DDL_PERMISSIONS`: Control DDL permissions per schema (CREATE, ALTER, DROP, TRUNCATE)
### Global Permission Defaults
- `ALLOW_INSERT_OPERATION`: Global default for INSERT permissions
- `ALLOW_UPDATE_OPERATION`: Global default for UPDATE permissions
- `ALLOW_DELETE_OPERATION`: Global default for DELETE permissions
- `ALLOW_DDL_OPERATION`: Global default for DDL permissions
## Security Considerations
1. **Default to Principle of Least Privilege**: By default, all write operations are disabled globally and must be explicitly enabled.
2. **Isolation in Multi-DB Mode**: Consider using a dedicated MySQL user with limited database grants when using multi-DB mode.
3. **Careful with DDL Permissions**: DDL operations can modify database structure, so grant these permissions cautiously.
4. **Production Databases**: Always set `schema:false` for production database schemas in all write permission settings.
5. **User Least Privilege**: Ensure the MySQL user only has the required permissions on the specific databases needed.