Skip to content
shellhacks.dev

Database URL Parser

Parse a DATABASE_URL for PostgreSQL, MySQL, Redis or MongoDB into host, port, user, password and options, and convert it to Laravel, Django, JDBC and CLI formats.

Free · No sign-up · Your inputs stay in your browser

Input

Parse a database connection URL

Output

Components

Enginepostgres
Hostdb.internal.example.com
Port5432
Userapp_user
Password•••••••••
Databaseapp_production
?sslmoderequire
?application_nameweb

Laravel .env

DB_CONNECTION=pgsql DB_HOST=db.internal.example.com DB_PORT=5432 DB_DATABASE=app_production DB_USERNAME=app_user DB_PASSWORD=•••••••• DB_SSLMODE=require

Django settings

DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", "HOST": "db.internal.example.com", "PORT": "5432", "NAME": "app_production", "USER": "app_user", "PASSWORD": "••••••••", "OPTIONS": {"sslmode": "require", "application_name": "web"}, } }

JDBC

jdbc:postgresql://db.internal.example.com:5432/app_production?sslmode=require&application_name=web

CLI

PGPASSWORD='••••••••' psql -h db.internal.example.com -p 5432 -U app_user -d app_production

Percent-encoded characters in the user and password are decoded: a password containing @, / or : has to be encoded in the URL, as %40, %2F and %3A, or the parser splits it in the wrong place. That is the usual reason a DATABASE_URL that looks right fails to connect.

Runs in this browser. Nothing you paste is sent to a server.

Percent-encoding is the usual bug

A URL reserves @, :, / and ? as separators, so a password containing any of them must be percent-encoded (@ as %40, / as %2F), or the parser splits the URL in the wrong place and the error mentions an unknown host. Hosting providers that hand out a DATABASE_URL encode it for you; one assembled by hand often is not. RFC 3986 defines the syntax.

Laravel reads it directly

Laravel's database config accepts a DB_URL (DATABASE_URL in older versions) and splits it with the same rules, so a provider's URL can be used as is. Explicit DB_HOST style variables are easier to read and override one at a time.

Share

Frequently asked questions

What port is used when the URL has none?
The engine's default: 5432 for PostgreSQL, 3306 for MySQL and MariaDB, 6379 for Redis, 27017 for MongoDB. The parser shows which it assumed.
What does sslmode=require do in a Postgres URL?
It makes the client use TLS but not verify the server's certificate. verify-full also checks the certificate and host name, which is what protects against interception.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Keep planning

Similar tools