Localhost Database Connection Strings for Development
Quick-reference localhost connection strings for all major databases. Copy-paste ready defaults for PostgreSQL, MySQL, MongoDB, Redis, SQLite, and MSSQL.
Detailed Explanation
Local Development Defaults
During development, you typically connect to databases running on your local machine. Here are copy-paste ready connection strings for each database with their standard defaults.
PostgreSQL
postgresql://postgres:postgres@localhost:5432/devdb
Default installation creates a postgres superuser. Common package manager installations:
- macOS (Homebrew):
brew install postgresql@16— starts on port 5432, userpostgresor your OS username - Ubuntu/Debian:
sudo apt install postgresql— userpostgres, authenticate viasudo -u postgres psql - Docker:
docker run -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:16
MySQL
mysql://root:password@localhost:3306/devdb
MySQL defaults to root user. The default password depends on installation:
- macOS (Homebrew): No password by default
- Ubuntu/Debian: Set during installation
- Docker:
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql:8
MongoDB
mongodb://localhost:27017/devdb
MongoDB's default installation has no authentication enabled. For authenticated development:
mongodb://admin:password@localhost:27017/devdb?authSource=admin
Redis
redis://localhost:6379/0
Redis defaults to no authentication. For password-protected Redis:
redis://:mypassword@localhost:6379/0
SQLite
file:./dev.db
No server needed — just a file path. For in-memory testing:
file::memory:
MSSQL
sqlserver://sa:YourStr0ngP@ssword@localhost:1433;database=devdb;trustServerCertificate=true
SQL Server requires a strong password for the sa account (minimum 8 characters with uppercase, lowercase, and digits).
Docker Compose All-in-One
A common development setup runs all databases in Docker Compose:
services:
postgres:
image: postgres:16
ports: ["5432:5432"]
environment:
POSTGRES_PASSWORD: postgres
mysql:
image: mysql:8
ports: ["3306:3306"]
environment:
MYSQL_ROOT_PASSWORD: password
mongo:
image: mongo:7
ports: ["27017:27017"]
redis:
image: redis:7
ports: ["6379:6379"]
.env File Template
POSTGRES_URL="postgresql://postgres:postgres@localhost:5432/devdb"
MYSQL_URL="mysql://root:password@localhost:3306/devdb"
MONGO_URL="mongodb://localhost:27017/devdb"
REDIS_URL="redis://localhost:6379/0"
SQLITE_URL="file:./dev.db"
Use Case
Quickly setting up a local development environment with copy-paste database connection strings, or configuring a .env file for a new project that needs multiple database connections.