MCP Server for MariaDB/MySQL
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Server for MariaDB/MySQL describe the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Server for MariaDB/MySQL
A Model Context Protocol (MCP) server that provides database access to MariaDB and MySQL databases. This server enables Claude Code and other MCP clients to interact with your databases through a secure, standardized interface.
Features
Database Operations: Execute SQL queries, list tables, and inspect table structures
Multiple Database Support: Switch between databases on the same connection
Secure Connection: Support for both local and remote database connections
MCP Standard Compliance: Built with official
@modelcontextprotocol/sdkTypeScript: Fully typed for better development experience
Related MCP server: mcp-mssql-server
Installation
From source
git clone https://github.com/Zdendys79/mcp-server-mariadb.git
cd mcp-server-mariadb
npm install
npm run buildConfiguration
Claude Code Configuration
Add this to your global Claude Code configuration file (~/.claude.json):
{
"mcpServers": {
"mariadb": {
"command": "node",
"args": ["/home/user/mcp-servers/mariadb/dist/index.js"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "3306",
"DB_USER": "your_database_user",
"DB_PASS": "your_database_password",
"DB_NAME": "your_database_name"
}
}
}
}Note on credentials:
✅ Safe: Credentials in
~/.claude.json(global config, outside project, not versioned)⚠️ Advanced: Use wrapper scripts + environment variables (see Advanced Configuration below)
❌ Never: Store credentials in project files (would be versioned in git)
Multiple Database Connections
You can configure multiple MCP server instances to connect to different databases simultaneously. This is useful when working with both local and remote databases, or multiple database servers.
Example: Local database + SSH-tunneled remote database
{
"mcpServers": {
"mariadb-local": {
"command": "node",
"args": ["/home/user/mcp-servers/mariadb/dist/index.js"],
"env": {
"DB_HOST": "127.0.0.1",
"DB_PORT": "3306",
"DB_USER": "local_user",
"DB_PASS": "local_password",
"DB_NAME": "local_database"
}
},
"mariadb-remote": {
"command": "node",
"args": ["/home/user/mcp-servers/mariadb/dist/index.js"],
"env": {
"DB_HOST": "127.0.0.1",
"DB_PORT": "3336",
"DB_USER": "remote_user",
"DB_PASS": "remote_password",
"DB_NAME": "remote_database"
}
}
}
}Note: When using SSH tunnels, set up the tunnel first:
ssh -L 3336:localhost:3306 user@remote-server -N -fThen configure the MCP server to connect to 127.0.0.1:3336.
Environment Variables
Database Connection
DB_HOST- Database host (default:127.0.0.1)DB_PORT- Database port (default:3306)DB_USER- Database username (default:claude_mcp)DB_PASS- Database password (default: empty string)DB_NAME- Database name (optional)If set (non-empty): Database is automatically selected on startup - no need to call
switch_databaseIf empty or not set: You must use the
switch_databasetool before executing queries
Connection Pool Settings (Advanced)
POOL_CONNECTION_LIMIT- Maximum number of connections in pool (default:10)POOL_QUEUE_LIMIT- Maximum number of queued connection requests (default:0= unlimited)POOL_WAIT_FOR_CONNECTIONS- Wait for available connection when pool is full (default:true)
When to adjust pool settings:
High concurrent usage → increase
POOL_CONNECTION_LIMITMemory constraints → decrease
POOL_CONNECTION_LIMITPrevent queue buildup → set
POOL_QUEUE_LIMIT> 0
Available Tools
list_databases
Lists all available databases on the server.
No parameters requiredswitch_database
Switches to a different database.
{
"database": "your_database_name"
}When to use:
Required: When no database is selected yet (DB_NAME not set and no previous switch_database call)
Optional: To change from currently active database to a different one
Not needed: If DB_NAME is set or database was already selected via previous switch_database call
Note: This overrides any database set via DB_NAME env variable. The newly selected database remains active until another switch_database call.
get_current_database
Returns the currently selected database name.
No parameters requiredlist_tables
Lists all tables in the currently selected database.
No parameters requiredNote: Requires an active database. Database is active when set via DB_NAME env var OR selected via switch_database tool.
describe_table
Shows the structure of a specific table.
{
"table": "table_name"
}Note: Requires an active database. Database is active when set via DB_NAME env var OR selected via switch_database tool.
execute_sql
Executes a SQL query on the currently selected database.
{
"query": "SELECT * FROM users LIMIT 10"
}Note: Requires an active database. Database is active when set via DB_NAME env var OR selected via switch_database tool.
Usage Example
Once configured, you can use Claude Code to interact with your database:
You: Show me all tables in the 'production' database
Claude: [Uses switch_database tool with database="production"]
[Uses list_tables tool]
Here are the tables in your production database:
- users
- orders
- products
...
You: What's the structure of the users table?
Claude: [Uses describe_table tool with table="users"]
The users table has the following columns:
- id (INT, PRIMARY KEY)
- username (VARCHAR(255))
- email (VARCHAR(255))
...Security Considerations
Database Credentials
Safe credential storage:
✅ Global config:
~/.claude.json(outside projects, not versioned in git)✅ Environment variables:
~/.profileor~/.config/environment.d/*.conf✅ Wrapper scripts: Load credentials from environment (advanced)
Never:
❌ Project files: Don't store credentials in project directories (would be versioned)
❌ Git repositories: Never commit credentials to version control
❌ Hardcoded: Don't hardcode credentials in source code
Best practices:
Use read-only users: Create dedicated database user with limited permissions
Network security: Use SSH tunnels or VPNs for remote database connections
Minimal permissions: Grant only necessary database privileges
Example: SSH Tunnel Setup
For secure remote access, set up an SSH tunnel:
ssh -L 3306:localhost:3306 user@remote-serverThen configure the MCP server to connect to localhost:3306.
Recommended Database User Permissions
Create a dedicated user with minimal permissions:
CREATE USER 'mcp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT SELECT ON your_database.* TO 'mcp_user'@'localhost';
GRANT SHOW DATABASES ON *.* TO 'mcp_user'@'localhost';
FLUSH PRIVILEGES;Adjust permissions based on your needs (add INSERT, UPDATE, DELETE if required).
Development
Building
npm run buildRunning locally
npm startProject Structure
mcp-server-mariadb/
├── src/
│ └── index.ts # Main server implementation
├── dist/ # Compiled JavaScript (generated)
├── examples/
│ └── legacy/ # Legacy bash implementation
├── .mcp.json.template # Configuration template
├── package.json
├── tsconfig.json
└── README.mdTroubleshooting
Connection Issues
Error: ER_ACCESS_DENIED_ERROR
Check your
DB_USERandDB_PASSenvironment variablesVerify the user has permission to connect from your host
Error: ECONNREFUSED
Check if MariaDB/MySQL is running
Verify
DB_HOSTandDB_PORTare correctCheck firewall rules
"No database selected" Error
You must call the switch_database tool before using list_tables, describe_table, or execute_sql.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Fork the repository
Create your feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add some amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Built with the Model Context Protocol SDK
Uses mysql2 for database connectivity
Support
Issues: https://github.com/Zdendys79/mcp-server-mariadb/issues
Discussions: https://github.com/Zdendys79/mcp-server-mariadb/discussions
Advanced Configuration
Using Environment Variables with Wrapper Scripts
For advanced use cases where you want to manage credentials centrally via environment variables, you can use wrapper scripts.
1. Create environment config file:
~/.profile (loaded for all sessions):
# MariaDB credentials for MCP
export MARIADB_LOCAL_USER="claude"
export MARIADB_LOCAL_PASS="your_password"
export MARIADB_LOCAL_DB="local_database"
export MARIADB_BASE7_USER="claude"
export MARIADB_BASE7_PASS="your_password"
export MARIADB_BASE7_DB="dh_scribe"OR ~/.config/environment.d/mariadb.conf (systemd user session, for GUI apps):
MARIADB_LOCAL_USER=claude
MARIADB_LOCAL_PASS=your_password
MARIADB_LOCAL_DB=local_database
MARIADB_BASE7_USER=claude
MARIADB_BASE7_PASS=your_password
MARIADB_BASE7_DB=dh_scribe2. Create wrapper scripts (examples in project repository):
mcp-mariadb-local.sh- loadsMARIADB_LOCAL_*variablesmcp-mariadb-base7.sh- loadsMARIADB_BASE7_*variables
3. Use wrapper scripts in ~/.claude.json:
{
"mcpServers": {
"mariadb-local": {
"command": "/home/user/mcp-servers/mariadb/mcp-mariadb-local.sh",
"args": []
},
"mariadb-base7": {
"command": "/home/user/mcp-servers/mariadb/mcp-mariadb-base7.sh",
"args": []
}
}
}Benefits:
Centralized credential management
Credentials outside config files
Reusable across multiple tools
When to use:
Multiple projects sharing same database credentials
Corporate environments with centralized credential management
When you want credentials in system environment variables
When NOT to use:
Simple single-user setup → just use
~/.claude.jsondirectlyCredentials already secure in
~/.claude.json→ no need for extra complexity
Changelog
See CHANGELOG.md for version history and changes.
Available Tools
6 toolsdescribe_tableC
Show the structure of a table
Inputs: table (required).
execute_sqlC
Execute a SQL query on the MariaDB database
Inputs: query (required).
get_current_databaseA
Get the name of the currently selected database
Inputs: no named parameters.
list_databasesA
List all available databases
Inputs: no named parameters.
list_tablesB
List all tables in the current database
Inputs: no named parameters.
switch_databaseA
Switch to a different database. Must be called before executing queries.
Inputs: database (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a clearly distinct operation: executing queries, listing tables, describing structure, listing databases, switching context, and reading current context. The only surface overlap (list_tables vs list_databases) is resolved by their distinct resources. No two tools could be reasonably confused.
All six tools follow a strict snake_case verb_noun pattern (execute_sql, list_tables, describe_table, list_databases, switch_database, get_current_database). The convention is uniform and predictable throughout.
Six tools is well-scoped for a database interaction server, covering the essential query and inspection operations without redundancy. Each tool earns its place and nothing feels padded or missing.
execute_sql as a catch-all gives full CRUD/DML capability, and metadata tools cover discovery and schema inspection. Minor gaps exist around index/schema detail beyond describe_table and explicit transaction/session management, but these are workaroundable via raw SQL.
Maintenance
Related MCP Connectors
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables LLMs and agents to interact with relational databases (SQL Server, MySQL, PostgreSQL) through MCP tools. Supports executing queries, inserting records, listing tables, and exposing database schemas with secure credential management.-
- AlicenseNot gradedqualityDmaintenanceEnables Claude Code and other MCP clients to interact with Microsoft SQL Server databases through standardized tools for query execution, schema exploration, table management, and stored procedure execution.1ISC
- AlicenseNot gradedqualityBmaintenanceEnables Claude Code to securely interact with PostgreSQL, MySQL, SQLite, and SQL Server databases, featuring read-only mode, query validation, SSH tunneling, and field redaction for production-safe data access.4MIT
- AlicenseNot gradedqualityBmaintenanceEnables Claude and other MCP clients to map a SQLite database's schema and run read-only SQL queries against it, with writes blocked at the SQLite level through multiple enforcement layers. Results come back as context-friendly Markdown tables with row caps and a query timeout.2MIT