One-Shot Query vs Interactive REPL: DB CLIs Fork on One Flag
After connecting, DB CLIs fork on one thing: pass a query flag for a one-shot run, omit it to drop into a REPL. Plus the psql/mysql/mongosh flags and clean-output options.
After connecting (same five coordinates), the only fork is whether you pass a query flag:
| One-shot (stay in shell) | Interactive (REPL) | |
|---|---|---|
| psql | -c "…" / -f file | psql <uri> → dbname=#, quit \q |
| mysql | -e "…" / < file | mysql <flags> → mysql>, quit exit |
| mongosh | --eval "…" / --file | mongosh <uri> → >, quit Ctrl-D |
The language inside the REPL differs: psql / mysql are SQL (mysql needs a trailing ;; psql’s \ meta-commands take no ;); mongosh is a JavaScript REPL wired to db. For scripting, add clean-output flags: psql -tA, mysql -BN, mongosh --quiet.
From this session: psql … -c "\dt" ran a backslash meta-command one-shot (no ;) and returned to the shell, and \dt only lists the search-path schema (public), while \dt *.* lists all schemas.
The only fork after connecting is the query flag: with one it’s one-shot, without one it’s a REPL.
References
- psql documentation: https://www.postgresql.org/docs/current/app-psql.html
Related: back to the remote DB overview; this runs on the five coordinates, and the MySQL side is four ways to feed inline SQL.