Database Connection String Formats Cheat Sheet
Connection string and URI formats across major databases covering PostgreSQL, MySQL, MongoDB, Redis, and driver-specific parameters.
1 PageBeginnerFeb 10, 2026
PostgreSQL & MySQL URIs
Standard connection URI formats for the two most common relational databases.
bash
# PostgreSQLpostgresql://user:password@host:5432/dbname?sslmode=requirepostgres://user:password@host:5432/dbname # short scheme also accepted# Postgres with connection pooling paramspostgresql://user:pass@host:5432/dbname?sslmode=require&connect_timeout=10&application_name=api# MySQLmysql://user:password@host:3306/dbname?ssl-mode=REQUIRED# Unix socket (no host/port)postgresql://user:password@/dbname?host=/var/run/postgresql
MongoDB & Redis URIs
Connection formats for common NoSQL / in-memory stores.
bash
# MongoDB standardmongodb://user:password@host1:27017,host2:27017/dbname?replicaSet=rs0&authSource=admin# MongoDB Atlas (SRV record, resolves hosts automatically)mongodb+srv://user:password@cluster0.mongodb.net/dbname?retryWrites=true&w=majority# Redisredis://:password@host:6379/0# Redis with TLSrediss://user:password@host:6380/0# Redis Sentinel (driver-specific, not a single URI in most clients)# sentinels: [{host: 's1', port: 26379}], name: 'mymaster'
Env Var & ORM Config Patterns
How connection strings typically flow into application config.
bash
# .envDATABASE_URL=postgresql://app:secret@db.internal:5432/app_prod?sslmode=requireREDIS_URL=redis://cache.internal:6379/0# Prisma (schema.prisma)# datasource db {# provider = "postgresql"# url = env("DATABASE_URL")# }# SQLAlchemy# engine = create_engine(os.environ["DATABASE_URL"])# Node pg# const pool = new Pool({ connectionString: process.env.DATABASE_URL })
Anatomy of a Connection URI
The generic components shared across most database URI schemes.
- scheme- protocol identifier, e.g. postgresql://, mysql://, mongodb+srv://
- userinfo- user:password@ segment; must be URL-encoded if it contains special characters
- host:port- can be a comma-separated list for replica sets / clusters
- path- the database/schema name, e.g. /dbname
- query params- driver options like sslmode, authSource, replicaSet, connect_timeout
- sslmode=require vs verify-full- require encrypts but doesn't verify cert identity; verify-full also checks the CA chain and hostname
Pro Tip
URL-encode special characters in passwords (`@`, `:`, `/`, `#`) before putting them in a connection string — an unescaped `@` in a password is silently parsed as the host separator, causing confusing 'could not connect to host' errors instead of an auth failure.
Was this cheat sheet helpful?
Explore Topics
#DatabaseConnectionStringFormats#DatabaseConnectionStringFormatsCheatSheet#Database#Beginner#PostgreSQLMySQLURIs#MongoDBRedisURIs#Env#Var#Databases#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance