Database connection string builder

Build the connection string for PostgreSQL, MySQL, SQL Server, MongoDB and Redis in the forms your driver reads (URI, JDBC, ADO.NET, ODBC, libpq

loading Database connection string builder
About this tool

What does a database connection string builder do?

Every database driver wants to be told where the server is and how to log in, and each one has its own way of writing it. PostgreSQL has a URI and a keyword form, Java wants JDBC, .NET wants ADO.NET, Python often wants a SQLAlchemy URL, and SQL Server also speaks ODBC. The pieces are the same: host, port, database, user, password, encryption. The punctuation is not.

The hard part is the password. In a URI, characters such as @, :, /, ?, # and % have a meaning, so a password like p@ss:w/rd?# breaks the string unless each character is percent-encoded. In an ADO.NET string a semicolon or a quote must be wrapped, and in a JDBC SQL Server URL a closing brace must be doubled. This tool applies the right rule for each format, so the driver reads back exactly what you typed.

You fill in one form and get every format for the engine you chose: PostgreSQL, MySQL, SQL Server, MongoDB or Redis. You also get a ready export line for an environment variable. Everything is built in your browser. The host, user and password are never uploaded. Only the engine and the encryption choice are remembered between visits; the rest stays on the page. If you want to inspect a URI you already have, the URL parser splits it into parts, and the URL encoder does the percent-encoding by hand.

How to build a connection string

  1. Choose the database at the top: PostgreSQL, MySQL, SQL Server, MongoDB or Redis. The port field shows the default as a placeholder (5432, 3306, 1433, 27017, 6379), so leave it empty unless your server uses another one.
  2. Type the host. It can carry its own port, as in db.example.com:6543, and an IPv6 address goes in brackets. For MongoDB the field is "Hosts (several for a replica set)" and takes a comma-separated list.
  3. Fill in the database (for Redis it is "Database number"), the user and the password. The password is hidden; turn on "Show the password" to check it.
  4. Pick the encryption under "Encryption (TLS)": off, on without checking the certificate, or on checking the certificate. Each format gets its own spelling of the same choice.
  5. Optionally add an application name and a connection timeout in seconds. For MongoDB you can also give a replica set name and an authentication database, or turn on "Use a DNS seed list (mongodb+srv)".
  6. Copy the string your driver expects from the list of results, or copy the environment variable line. Put the value in a secret store, not in code.

If the page shows a message in red, no strings are produced until you fix it. See the section on errors below. Need a strong password for the account first? The token generator makes one. The strings fit nicely in a Compose file; the docker run to Compose converter shows how containers receive them.

Examples

PostgreSQL with a password full of symbols

Host db.example.com, database app, user admin, password p@ss:w/rd?#, encryption on. The URI form percent-encodes the password, while the libpq keyword form leaves it as is.

postgresql://admin:p%40ss%3Aw%2Frd%3F%23@db.example.com:5432/app?sslmode=require
host=db.example.com port=5432 dbname=app user=admin password=p@ss:w/rd?# sslmode=require
jdbc:postgresql://db.example.com:5432/app?user=admin&password=p%40ss%3Aw%2Frd%3F%23&sslmode=require
Host=db.example.com;Port=5432;Database=app;Username=admin;Password=p@ss:w/rd?#;SSL Mode=Require
postgresql+psycopg://admin:p%40ss%3Aw%2Frd%3F%23@db.example.com:5432/app?sslmode=require

The three encryption choices map to sslmode=disable, require and verify-full.

SQL Server with a semicolon and a brace in the password

Password se;cret}, encryption on. Each format escapes it its own way: quotes in ADO.NET, doubled braces in JDBC and ODBC.

Server=tcp:db.example.com,1433;Initial Catalog=app;User ID=admin;Password="se;cret}";Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;
jdbc:sqlserver://db.example.com:1433;databaseName=app;user=admin;password={se;cret}}};encrypt=true;trustServerCertificate=true;
Driver={ODBC Driver 18 for SQL Server};Server=tcp:db.example.com,1433;Database=app;Uid=admin;Pwd={se;cret}}};Encrypt=yes;TrustServerCertificate=yes;

MongoDB Atlas with a DNS seed list

Host cluster0.abc.mongodb.net, database app, "Use a DNS seed list" on. The port is dropped, because the seed list takes none.

mongodb+srv://admin:secret@cluster0.abc.mongodb.net/app?tls=true&retryWrites=true&w=majority

With a replica set instead, hosts a.example.com, b.example.com:27018, replica set rs0 and authentication database admin give mongodb://admin:secret@a.example.com:27017,b.example.com:27018/app?replicaSet=rs0&authSource=admin&tls=true.

Redis with and without a user

A password only, no user and no encryption on localhost, database 0: redis://:secret@localhost:6379/0. With a user app and encryption on, the scheme becomes rediss: rediss://app:secret@db.example.com:6379/0.

Common errors and how to fix them

MessageWhat to do
The host must be a name or an IP address, with an optional :port. IPv6 goes in brackets.Remove spaces and symbols from the host; write [2001:db8::1]:6543 for IPv6.
Only MongoDB accepts several hosts.Keep a single host for the other engines.
The port must be a number from 1 to 65535.Fix the port, or leave it empty for the default.
The timeout must be a whole number of seconds from 0 to 3600.Use a whole number in that range.
The DNS seed list takes one host name and no port.Remove the port and extra hosts when mongodb+srv is on.
A Redis database is a number, usually 0 to 15.Type a number such as 0.

Two warnings may appear above the results. "This string holds the password in plain text" is a reminder to keep the value in a secret or an environment variable, never in a repository. "Encryption is off for a host that is not local" means the password and the data cross the network in the clear. Local hosts such as localhost do not trigger it. A third warning explains that StackExchange.Redis uses commas between settings, so a user or password with a comma cannot be written in that form; use the URI instead.

FAQ

Why is my password changed in the URI?

Characters like @, :, /, ?, # and % mean something in a URI, so they are written as %40, %3A and so on. The driver decodes them and reads your original password. The tool does this for you.

Which TLS option should I use?

Use "On, checking the certificate" for anything real; it protects against someone pretending to be the server. "On, without checking the certificate" encrypts the traffic but trusts any certificate, which is common in tests. Off is for a local machine.

Is the password stored or sent?

No. The string is built in your browser. Host, user and password are not saved between visits.

Can I paste the result into a config file?

You can, but prefer an environment variable or a secret manager. The tool writes a line such as export DATABASE_URL='...' with the value in single quotes, ready for a shell.

Why do some formats show a different default timeout?

Each driver has its own setting. The SQL Server strings include Connection Timeout=30, and the PostgreSQL ones add a timeout only when you enter one.

Report a problem