mcp-mysql-multi-db
v2.1.1
Published
A Model Context Protocol (MCP) server for MySQL database with multi-database support
Downloads
451
Maintainers
Readme
mcp-mysql-multi-db
A Model Context Protocol (MCP) server for MySQL database with multi-database support.
Features
- ✅ Multi-database support - Query multiple databases from a single MCP server
- ✅ Custom port support - Connect to MySQL on any port (not just 3306)
- ✅ Timezone support - Configure timezone for correct datetime display (default: China +08:00)
- ✅ Auto-reconnect - Automatically reconnect when connection is lost (e.g., after sleep/hibernate)
- ✅ BIGINT precision - Large numbers are returned as strings to avoid precision loss
- ✅ Query execution (SELECT)
- ✅ Data modification (INSERT, UPDATE, DELETE)
- ✅ List all tables
- ✅ Describe table structure
Installation
npx -y mcp-mysql-multi-dbConfiguration
Windsurf / Cursor IDE
Add to your MCP configuration file:
Windsurf: ~/.codeium/windsurf/mcp_config.json
Cursor: ~/.cursor/mcp.json
Single Database (backward compatible)
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "mcp-mysql-multi-db"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Multiple Databases (new feature)
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "mcp-mysql-multi-db"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASES": "clx_performance,purchase_manage"
}
}
}
}When multiple databases are configured, tools will be generated with database suffixes:
query_clx_performance,query_purchase_manageexecute_clx_performance,execute_purchase_managelist_tables_clx_performance,list_tables_purchase_managedescribe_table_clx_performance,describe_table_purchase_manage
Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| MYSQL_HOST | MySQL server hostname | localhost |
| MYSQL_PORT | MySQL server port | 3306 |
| MYSQL_USER | MySQL username | root |
| MYSQL_PASSWORD | MySQL password | (empty) |
| MYSQL_DATABASE | Single database name (backward compatible) | (empty) |
| MYSQL_DATABASES | Multiple database names, comma-separated | (empty) |
| MYSQL_TIMEZONE | Timezone for datetime fields (e.g., '+08:00', 'Asia/Shanghai') | +08:00 |
| ALLOW_DDL | Allow DDL operations (CREATE, ALTER, DROP, TRUNCATE, RENAME) | false |
| ALLOW_DML | Allow DML operations (INSERT, UPDATE, DELETE, REPLACE) | false |
Permission Control
By default, this MCP server runs in read-only mode. DDL and DML operations are disabled for safety.
To enable write operations, set the corresponding environment variables:
{
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"ALLOW_DML": "true",
"ALLOW_DDL": "true"
}
}Available Tools
query
Execute a SELECT query on the MySQL database.
SELECT * FROM users LIMIT 10execute
Execute INSERT, UPDATE, or DELETE queries.
INSERT INTO users (name, email) VALUES ('John', '[email protected]')list_tables
List all tables in the current database.
describe_table
Get the structure of a specific table.
Example Usage
After configuring the MCP server, you can use it in your AI assistant:
- "Show me all tables in the database"
- "Query the first 10 users"
- "Describe the orders table structure"
Why This Package?
Most MySQL MCP packages don't support custom ports. This package was created to solve that problem - simply set MYSQL_PORT environment variable to connect to MySQL on any port.
License
MIT
Author
wejack639
