
MariaDB MySQL数据库访问
STDIO安全访问MariaDB/MySQL数据库查询工具
安全访问MariaDB/MySQL数据库查询工具
MCP is certified by MCP Review https://mcpreview.com/mcp-servers/rjsalgado/mariadb-mcp-server
This MCP server provides access to MariaDB / MySQL databases.
It allows you to:
# Install globally npm install -g mariadb-mcp-server # Or install locally in your project npm install mariadb-mcp-server
# Clone the repository git clone https://github.com/rjsalgado/mariadb-mcp-server.git cd mariadb-mcp-server # Install dependencies and build npm install npm run build
The server requires the following environment variables:
Add the following configuration to your MCP settings file:
If you installed via npm (Option 1):
{ "mcpServers": { "mariadb": { "command": "npx", "args": ["mariadb-mcp-server"], "env": { "MARIADB_HOST": "your-host", "MARIADB_PORT": "3306", "MARIADB_USER": "your-user", "MARIADB_PASSWORD": "your-password", "MARIADB_DATABASE": "your-database", "MARIADB_ALLOW_INSERT": "false", "MARIADB_ALLOW_UPDATE": "false", "MARIADB_ALLOW_DELETE": "false", "MARIADB_TIMEOUT_MS": "10000", "MARIADB_ROW_LIMIT": "1000", }, "disabled": false, "autoApprove": [] } } }
If you built from source (Option 2):
{ "mcpServers": { "mariadb": { "command": "node", "args": ["/path/to/mariadb-mcp-server/dist/index.js"], "env": { "MARIADB_HOST": "your-host", "MARIADB_PORT": "3306", "MARIADB_USER": "your-user", "MARIADB_PASSWORD": "your-password", "MARIADB_DATABASE": "your-default-database", "MARIADB_ALLOW_INSERT": "false", "MARIADB_ALLOW_UPDATE": "false", "MARIADB_ALLOW_DELETE": "false", "MARIADB_TIMEOUT_MS": "10000", "MARIADB_ROW_LIMIT": "1000", }, "disabled": false, "autoApprove": [] } } }
"server_name": "mariadb" or "server_name": "mysql"
Lists all accessible databases on the MariaDB / MySQL server. Parameters: None
Example:
{ "server_name": "mariadb", "tool_name": "list_databases", "arguments": {} }
Lists all tables in a specified database.
Parameters:
database
(optional): Database name (uses default if not specified)Example:
{ "server_name": "mariadb", "tool_name": "list_tables", "arguments": { "database": "my_database" } }
Shows the schema for a specific table.
Parameters:
database
(optional): Database name (uses default if not specified)table
(required): Table nameExample:
{ "server_name": "mariadb", "tool_name": "describe_table", "arguments": { "database": "my_database", "table": "my_table" } }
Executes a SQL query.
Parameters:
query
(required): SQL querydatabase
(optional): Database name (uses default if not specified)Example:
{ "server_name": "mariadb", "tool_name": "execute_query", "arguments": { "database": "my_database", "query": "SELECT * FROM my_table LIMIT 10" } }
The server includes test scripts to verify functionality with your MariaDB / MySQL setup:
This script creates a test database, table, and sample data:
# Set your MariaDB / MySQL credentials as environment variables export MARIADB_HOST=localhost export MARIADB_PORT=3306 export MARIADB_USER=your_username export MARIADB_PASSWORD=your_password export MARIADB_ALLOW_INSERT: false export MARIADB_ALLOW_UPDATE: false export MARIADB_ALLOW_DELETE: false export MARIADB_TIMEOUT_MS=10000 export MARIADB_ROW_LIMIT=1000 # Run the setup script npm run test:setup
This script tests each of the MCP tools against the test database:
#### # Set your MariaDB / MySQL credentials as environment variables MARIADB_HOST=localhost MARIADB_PORT=3306 MARIADB_USER=your_username MARIADB_PASSWORD=your_password MARIADB_DATABASE=mcp_test_db MARIADB_ALLOW_INSERT=false MARIADB_ALLOW_UPDATE=false MARIADB_ALLOW_DELETE=false MARIADB_TIMEOUT_MS=10000 MARIADB_ROW_LIMIT=1000 MARIADB_DEBUG_SQL=true #### export MARIADB_HOST=localhost export MARIADB_PORT=3306 export MARIADB_USER=your_username export MARIADB_PASSWORD=your_password export MARIADB_DATABASE=mcp_test_db export MARIADB_ALLOW_INSERT: false export MARIADB_ALLOW_UPDATE: false export MARIADB_ALLOW_DELETE: false export MARIADB_TIMEOUT_MS=10000 export MARIADB_ROW_LIMIT=1000 # Run the tools test script npm run test:tools
To run both setup and tool tests:
# Set your MariaDB / MySQL credentials as environment variables export MARIADB_HOST=localhost export MARIADB_PORT=3306 export MARIADB_USER=your_username export MARIADB_PASSWORD=your_password export MARIADB_ALLOW_INSERT: false export MARIADB_ALLOW_UPDATE: false export MARIADB_ALLOW_DELETE: false export MARIADB_TIMEOUT_MS=10000 export MARIADB_ROW_LIMIT=1000 # Run all tests npm test
If you encounter issues:
Inspiration https://github.com/dpflucas/mysql-mcp-server
This project is licensed under the MIT License - see the LICENSE file for details.