Configuration Methods
DBHub supports two ways to provide database connection parameters via environment variables:- DSN string (recommended) - Single connection string
- Individual parameters - Separate variables for each connection detail
Use individual parameters when your password contains special characters (
@, :, /, #) that would break URL parsing in a DSN string..env File Loading
DBHub automatically loads environment variables from.env files:
Development mode (using tsx or NODE_ENV=development):
- Looks for
.env.localfirst - Falls back to
.env
- Only loads
.env
Database Connection
Method 1: DSN Connection String
The simplest approach - provide a single connection string:Complete database connection string in URL format.Format:
protocol://[user[:password]@]host[:port]/database[?options]DSN Examples by Database Type
Method 2: Individual Connection Parameters
When your password contains special characters, use individual parameters:Database type.Options:
postgres, mysql, mariadb, sqlserver, sqliteDatabase server hostname or IP address.Not required for SQLite.
Database server port number.Defaults:
- PostgreSQL:
5432 - MySQL/MariaDB:
3306 - SQL Server:
1433 - SQLite: Not applicable
Database username.Not required for SQLite.
Database password. Can contain any special characters.Not required for SQLite or Azure AD authentication.
Database name.For SQLite, this is the file path to the database.
Individual Parameters Examples
Transport Configuration
MCP server transport protocol.Options:
stdio- Standard input/output (for Claude Desktop, Claude Code, Cursor)http- HTTP transport with JSON responses (for network clients)
HTTP server port. Only used when
TRANSPORT=http.SSH Tunnel Configuration
Securely connect to databases through SSH bastion hosts:SSH server hostname or IP address. Can be an alias from
~/.ssh/config.SSH server port number.
SSH username for authentication.
SSH password authentication. Use either this or
SSH_KEY.Path to SSH private key file. Use either this or
SSH_PASSWORD.Supports ~/ expansion.Passphrase for encrypted SSH private key.
Comma-separated list of jump hosts for multi-hop SSH connections.Format:
[user@]host[:port],[user@]host[:port],...Seconds between SSH keepalive packets. Set to 0 to disable.
Maximum number of missed keepalive responses before disconnecting.
SSH Examples
Complete .env Example
A typical production setup:.env Template
Create a.env.example file in your repository as a template:
.env and fill in their values:
When to Use Environment Variables
Use environment variables when:- Deploying in containers (Docker, Kubernetes)
- Running in CI/CD pipelines
- Managing a single database connection
- Passwords contain special characters
- You want environment-specific configs (dev/staging/prod)
- Managing multiple databases
- Need per-tool settings (readonly, max_rows)
- Defining custom SQL tools
- Advanced SSH tunnel configurations
- Per-database timeouts or connection pooling
Configuration Priority
Remember that environment variables have lower priority than command-line arguments:- Command-line arguments (highest)
- TOML config file
- Environment variables ← You are here
.envfiles (lowest)
Command-line flags will override environment variables. This is useful for temporary testing without modifying your
.env file.Deprecated Variables
The following environment variables are no longer supported:Next Steps
Command-Line Flags
Override settings with command-line arguments
TOML Configuration
Set up multiple databases with advanced options