A Model Context Protocol (MCP) server for MySQL database with multi-database support
npm install mcp-mysql-multi-dbbash
npx -y mcp-mysql-multi-db
`
Configuration
$3
Add to your MCP configuration file:
Windsurf: ~/.codeium/windsurf/mcp_config.json
Cursor: ~/.cursor/mcp.json
#### Single Database (backward compatible)
`json
{
"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)
`json
{
"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_manage
- execute_clx_performance, execute_purchase_manage
- list_tables_clx_performance, list_tables_purchase_manage
- describe_table_clx_performance, describe_table_purchase_manage
$3
| 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:
`json
{
"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
$3
Execute a SELECT query on the MySQL database.
`sql
SELECT * FROM users LIMIT 10
`
$3
Execute INSERT, UPDATE, or DELETE queries.
`sql
INSERT INTO users (name, email) VALUES ('John', 'john@example.com')
`
$3
List all tables in the current database.
$3
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.