Credential Management
mxcli provides secure credential management for external database connections. Credentials are isolated from session output, logs, and error messages.
Security Principles
- DSN isolation – Connection strings (which contain passwords) are never displayed in session output
- Alias-only display –
SQL CONNECTIONSonly shows alias and driver type - Log sanitization – Credentials are stripped from log output and error messages
Connection Methods
Inline DSN
The simplest approach, suitable for development:
SQL CONNECT postgres 'postgres://user:password@localhost:5432/mydb' AS source;
Environment Variables
Store credentials in environment variables for CI/CD and production:
# Set environment variable
export MYDB_DSN='postgres://user:password@host:5432/mydb'
# Use in mxcli (depends on your shell expanding the variable)
SQL CONNECT postgres '$MYDB_DSN' AS source;
YAML Configuration
mxcli supports YAML configuration files for managing multiple database connections. The configuration file stores DSN information that can be referenced by name.
Configuration is resolved from:
- Environment variables
- YAML config files
- Inline DSN strings
CLI Subcommand
The mxcli sql subcommand accepts credentials via command-line flags:
mxcli sql --driver postgres --dsn 'postgres://user:pass@host:5432/db' "SELECT 1"
For CI/CD pipelines, use environment variables:
export DB_DSN='postgres://user:pass@host:5432/db'
mxcli sql --driver postgres --dsn "$DB_DSN" "SELECT * FROM users"
Best Practices
- Never commit credentials to version control
- Use environment variables in CI/CD pipelines
- Use YAML config for local development with multiple databases
- Rotate credentials regularly
- Use read-only database users when only querying (not importing)
Mendix Application Database
For IMPORT commands that write to the Mendix application database, the connection is automatically established using the project’s configuration settings (from DESCRIBE SETTINGS). The Mendix database DSN is built from the project’s DatabaseType, DatabaseUrl, DatabaseName, DatabaseUserName, and DatabasePassword settings.