usql

Universal command-line database client

TLDR

Connect to PostgreSQL
$ usql postgres://[user]:[pass]@[host]/[database]
Connect to MySQL
$ usql mysql://[user]:[pass]@[host]/[database]
Connect to SQLite
$ usql sqlite:[database.db]
Execute query
$ usql [connection_url] -c "[SELECT * FROM table]"
Execute file
$ usql [connection_url] -f [script.sql]
List databases
$ usql [connection_url] -c "\\l"
Describe table
$ usql [connection_url] -c "\\d [table_name]"

SYNOPSIS

usql [-c command] [-f file] [options] connectionurl_

DESCRIPTION

usql is a universal command-line interface for SQL databases. It connects to PostgreSQL, MySQL, SQLite, SQL Server, Oracle, and many other databases (including NoSQL databases) with a consistent psql-inspired interface.Connection strings follow URL format. The scheme identifies the database type: postgres://, mysql://, sqlite:, mssql://, oracle://, etc. When no scheme is given, usql auto-detects: directories use PostgreSQL, regular files use SQLite3 or DuckDB.Backslash commands work across databases: \\l lists databases, \\dt lists tables, \\d describes objects, \\drivers lists available database drivers.Query output can be formatted as tables, CSV, JSON, or other formats. Tab completion assists with table and column names, and history persists across sessions.

PARAMETERS

-c CMD

Execute command and exit.
-f FILE
Execute file.
-o FILE
Output to file.
-w, --no-password
Never prompt for password.
-W, --password
Always prompt for password.
-X, --no-rc
Don't read rc file.
-t, --tuples-only
Only print rows.
-q, --quiet
Quiet mode.
-v NAME=VALUE
Set variable.
--help
Show help.
--version
Show version.

INSTALL

nix profile install nixpkgs#usql

CAVEATS

Not all features available on all databases. Some drivers need installation. Complex queries may have database-specific syntax.

HISTORY

usql was created by Kenneth Shaw around 2017 to provide a universal SQL client. It addresses the fragmentation of database CLIs with a single, consistent tool.

SEE ALSO

psql(1), mysql(1), sqlite3(1), sqlcmd(1)