Skip to main content

Database Connection String Builder

Build a database connection URI and .env-style config from host, port and credential fields — PostgreSQL, MySQL, MariaDB, MongoDB, Redis, MSSQL and SQLite. Handles URL-encoding of special characters, IPv6 hosts and Unix socket paths automatically.

Input

Only PostgreSQL, MySQL and MariaDB support Unix domain sockets here.

IPv6 addresses (e.g. ::1) are wrapped in brackets automatically.

Leave blank to use the selected database's default port.

For Redis this is the numeric DB index (0-15). Optional — omit to use the driver's default.

URL-encoded automatically wherever it appears in the URI — safe to use @, :, / or # in it.

PostgreSQL: sslmode=require · MySQL/MariaDB: ssl=true · MongoDB: tls=true · Redis: rediss:// · MSSQL: encrypt=true

Optional. One key=value pair per line, appended as extra query-string parameters.

Output

Connection URI
 
.env / Keyword-Value Format
 

DATABASE_URL plus the same values decomposed into individual DB_* variables.

Was this helpful?

Guides

The Database Connection String Builder turns plain host, port, and credential fields into a correctly formatted connection URI — for PostgreSQL, MySQL, MariaDB, MongoDB, Redis, Microsoft SQL Server, and SQLite. It also produces a ready-to-paste .env block with DATABASE_URL and the individual DB_HOST, DB_PORT, DB_NAME, DB_USER, and DB_PASSWORD values decomposed.

Every database driver has its own URI scheme, its own default port, and its own rules for what needs percent-encoding. A password containing @, :, /, or # silently breaks a hand-typed connection string unless every reserved character is escaped — one of the most common causes of a "connection refused" or authentication error that has nothing to do with the actual credentials. This tool encodes special characters automatically, so you never have to remember which characters are safe.

How to use it

  1. Pick a database type. The form adapts — SQLite swaps host/port for a file path; MySQL and PostgreSQL offer a Unix socket option.
  2. Fill in host, port (leave blank to use the database's default), database name, username, and password.
  3. Toggle Use SSL/TLS if your connection requires encryption.
  4. Copy the Connection URI for your ORM/driver config, or the .env block to paste straight into a .env file.

What it handles

  • URL-encoding — usernames, passwords, and the database name are percent-encoded wherever they appear in the URI, so special characters like @, :, /, and # in a password never break the string.
  • IPv6 hosts — an address like ::1 or 2001:db8::1 is automatically wrapped in brackets ([::1]), as required by the URI spec.
  • Unix domain sockets — PostgreSQL, MySQL, and MariaDB support a socket-path connection mode in place of host/port.
  • MongoDB SRV records — a "Use SRV connection" toggle produces a mongodb+srv:// URI (no port) for services like MongoDB Atlas.
  • SQLite paths — relative and absolute file paths get the correct slash-count convention (sqlite:///relative/path.db vs sqlite:////absolute/path.db), the format SQLAlchemy and many other SQLite URI parsers expect.

Why does the URI scheme say mysql:// for MariaDB?

MariaDB is wire-compatible with MySQL, and every mainstream driver and ORM (Prisma, Sequelize, Knex, node-mysql2) accepts the same mysql:// scheme for both — there is no separate, widely-adopted mariadb:// scheme.

What about Microsoft SQL Server?

Many Node.js and Python drivers accept the mssql:// URI this tool generates, but SQL Server tooling on Windows/.NET more commonly uses ADO.NET keyword syntax instead (Server=host,port;Database=db;User Id=user;Password=pass;). Use the generated host/port/username/password values to build that format if your driver expects it.

Is a Unix socket path's query-string format standardized?

Not universally. PostgreSQL's ?host=/socket/dir convention is documented in the official libpq URI spec; MySQL/MariaDB drivers vary (some read ?socket=, others take a separate connection option entirely) — check your specific driver's documentation before relying on the generated socket URI verbatim.

Privacy

This tool runs entirely in your browser — the host, credentials, and generated connection strings are never sent to a server. To parse an existing .env file instead of building one, use the Env File Parser. To URL-encode a password or other value on its own, use the URL Encoder/Decoder.

postgrespostgresqlmysqlmariadbmongodbredismssqlsql serversqlitedsndatabase urlenvdotenvconnection uriconnection string

Use it from code

From 3 credits per call

REST API

curl -X POST https://api.iotools.cloud/v1/tool/database-connection-string-builder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "dbType": "postgresql",
    "connectionMode": "tcp",
    "host": "db.example.com",
    "socketPath": "",
    "port": "",
    "mongoSrv": "",
    "database": "myapp",
    "filePath": "",
    "username": "app_user",
    "password": "p@ss:w/ord#1",
    "ssl": "true",
    "extraParams": ""
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `database-connection-string-builder` tool (Database Connection String Builder) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.