Engineering · 1 min read
The Connection URI Is Canonical; Flags Are It Decomposed
One connection URI carries all five coordinates and looks identical across engines. CLI flags are just that URI taken apart, with casing traps like -P port vs -p password.
One URI shape carries all five coordinates and looks identical across engines:
scheme://user:password@host:port/database
- Postgres:
postgresql://u:[email protected]:5432/db - Mongo:
mongodb://u:[email protected]:27017/db - MySQL: same shape conceptually, but the
mysqlCLI only takes flags.
CLI flags are just this URI taken apart: -h=host, and port / user / db are the rest. The real trap is casing collisions:
- psql:
-p=port (lower),-U=user (upper), no password-value flag (usePGPASSWORDor the URI). - mysql:
-P=port (UPPER),-p=password glued on (-pSecret; a space makes it the database name),-u=user.
From this session: psql postgresql://postgres:[email protected]:5433/demo_db worked verbatim, proof that using the URI sidesteps all flag-guessing.
Remember one URI; flags are just it taken apart. When unsure of a flag, hand it the URI.
References
- PostgreSQL libpq connection: https://www.postgresql.org/docs/current/libpq-connect.html
- Postgres connection strings and psql: https://tapoueh.org/blog/2019/09/postgres-connection-strings-and-psql/
Related: back to the remote DB overview; see the five coordinates and the MySQL CLI flags.