USQL(1)
π¦ NAME π¦
okay so bestie, meet usql β a universal command-line interface for SQL, NoSQL, and other databases. yes, universal. it does the most, in the best way. π
β¨ DESCRIPTION β¨
usql is a universal command-line interface for PostgreSQL, MySQL, MariaDB, Oracle Database, TiDB, SQLite3, Microsoft SQL Server, and so many other databases β including NoSQL and non-relational databases! it was Inspired by PostgreSQL's powerful command-line tool psql. like, inspired-inspired. π«Ά
usql gives you a simple way to interact with a whole bunch of database systems through one consistent interface. it supports most core psql features β variables, backticks, and backslash commands, all of it β while adding unique capabilities like syntax highlighting, context-based completion, native multi-database support via standard URL connection strings, copying data between different database systems, terminal graphics support, and more. the way it just does all that? iconic. π
Database administrators and developers who prefer a psql-like experience for non-PostgreSQL databases will find usql intuitive and powerful. it supports connecting to various database drivers (see the \drivers command within usql), executing SQL commands, running scripts from files, and formatting output in various styles (aligned, unaligned, HTML, JSON, CSV, vertical, etc.). pick a vibe, any vibe. π
π OPTIONS π
-c,--command COMMANDβ run only single command (SQL or internal) and exit. one and done, periodt.-f,--file FILEβ execute commands from file and exit-w,--no-passwordβ never prompt for password-X,--no-initβ do not execute initialization scripts (aliases:--no-rc--no-psqlrc--no-usqlrc)-o,--out FILEβ output file-W,--passwordβ force password prompt (should happen automatically)-1,--single-transactionβ execute as a single transaction (if non-interactive)-v,--set NAME=VALUEβ set variable NAME to VALUE (see\setcommand, aliases:--var--variable)-N,--cset NAME=DSNβ set named connection NAME to DSN (see\csetcommand)-P,--pset VAR=ARGβ set printing option VAR to ARG (see\psetcommand)-F,--field-separator FIELD-SEPARATORβ field separator for unaligned and CSV output (default"|"and",")-R,--record-separator RECORD-SEPARATORβ record separator for unaligned and CSV output (default\n)-T,--table-attr TABLE-ATTRβ set HTML table tag attributes (e.g., width, border)-A,--no-alignβ unaligned table output mode-H,--htmlβ HTML table output mode-t,--tuples-onlyβ print rows only-x,--expandedβ turn on expanded table output-z,--field-separator-zeroβ set field separator for unaligned and CSV output to zero byte-0,--record-separator-zeroβ set record separator for unaligned and CSV output to zero byte-J,--jsonβ JSON output mode-C,--csvβ CSV output mode-G,--verticalβ vertical output mode-q,--quietβ run quietly (no messages, only query output)--config stringβ config file-V,--versionβ output version information, then exit-?,--helpβ Show this help, then exit.
πΈ CONNECTING TO DATABASES πΈ
usql connects to databases using Data Source Name (DSN) URLs, typically in the format:
driver[+transport]://[user[:pass]@][host][:port][/dbname][?opt1=val1&opt2=val2]
Where:
- driver β Is the primary scheme or alias for the database driver (e.g.,
postgres,pg,mysql,my,sqlserver,ms,oracle,or,sqlite3,sq,csvq). Use the\driverscommand inusqlto see available drivers and aliases. - transport β Is optional, usually
tcp,udp, orunix. Some drivers like ODBC use it for sub-protocol specification. - user, pass, host, port β Are standard connection credentials. Many parts are optional and defaults may apply (e.g., connecting via local Unix sockets).
- dbname β Represents the database name, service ID, instance, or sometimes a file path (for file-based databases like SQLite3 or DuckDB). For some drivers (e.g., SQL Server, Oracle), this can be
/instance/dbname. - ?opt1=val1... β Are driver-specific connection options passed as URL query parameters.
usql can also connect to local files directly (e.g., /path/to/db.sqlite3) or named connections defined in the configuration file. lowkey convenient. π
See the project's README.md for detailed examples and supported drivers.
π COMMANDS π
usql interprets backslash (\) commands for meta-operations, similar to psql. These provide functionality beyond standard SQL. Use \? within usql for a full list. Key commands include:
\c,\connect DSN | NAMEβ Connect to a database using a DSN URL or a pre-defined named connection.\copy SRC_DSN DST_DSN QUERY TABLE[(COLS)]β Copy data between databases. Executes QUERY on SRC_DSN and inserts results into TABLE on DST_DSN.\d[+] [PATTERN]β List tables, views, sequences. Add'+'for more detail. Many variants exist (\dt,\di,\f, n, etc.) to list specific object types. Use\? optionsfor details.\g,\go [(OPTIONS)] [FILE]β Execute the current query buffer, optionally sending results to a FILE or pipe.\G,\ego [(OPTIONS)] [FILE]β Execute query and force vertical output mode.\gx [(OPTIONS)] [FILE]β Execute query and force expanded output mode.\i,\include FILEβ Execute commands from FILE.\p,\print [-raw|-exec]β Show the contents of the query buffer (or the raw/exec buffer).\r,\resetβ Clear the query buffer.\set [NAME [VALUE]]β Set or show runtime variables. Used for query interpolation.\pset [NAME [VALUE]]β Set or show display formatting options (e.g., border, format, tuples_only).\cset [NAME [DSN]]β Set or show named connection DSNs.\timing [on|off]β Toggle display of command execution time.\! [COMMAND]β Execute a command in the system shell.\q,\quitβ Quitusql.
π¦ VARIABLES π¦
usql utilizes variables for configuration and dynamic query generation:
- Runtime Variables (
\set) β Set with\set NAME VALUE. Interpolated into queries using:NAME(direct substitution),:'NAME'(quoted as string literal), or:"NAME"(quoted as identifier). View all with\set. Unset with\unset NAME. - Connection Variables (
\cset) β Set with\cset NAME DSN. Provide aliases for database connection URLs used with\cor\copy. View all with\cset. Not used for query interpolation. - Display Formatting Variables (
\pset) β Set with\pset NAME VALUEor toggle commands like\a,\H,\x,\t. Control table borders, output formats (aligned, csv, html, json, etc.), titles, timing display, etc. View all with\pset. - Special variables (set via
\set) control behavior like syntax highlighting (SYNTAX_HL,SYNTAX_HL_STYLE), host info display (SHOW_HOST_INFORMATION), prompts (PROMPT1,PROMPT2,PROMPT3), etc. Use\? variablesinusqlfor a comprehensive list.
π FILES π
$HOME/.config/usql/config.yamlβ Primary configuration file (path varies by OS:%AppData%/usql/config.yamlon Windows,$HOME/Library/Application Support/usql/config.yamlon macOS). Defines named connections (connections:), startup commands (init:), default settings, etc. Uses YAML format.$HOME/.usqlrcβ Legacy startup script executed whenusqlstarts interactively, unless-Xis given. Useful for setting variables or running initial commands. Theinit:section inconfig.yamlis now preferred.$HOME/.usqlpassβ Legacy file for storing database passwords (permissions must be0600). Format:protocol:host:port:dbname:user:pass. Using named connections inconfig.yamlis generally safer and more flexible.
ngl bestie, those last two are giving legacy energy β config.yaml is the main character now. π
π ENVIRONMENT π
EDITORβ Specifies the editor used by the\ecommand.PAGERβ Specifies the pager program used for displaying help (\?) and other long output.SHELLβ Specifies the shell used by the\!command.USQL_CONFIG_DIRβ Overrides the default directory for configuration files (config.yaml,.usqlrc,.usqlpass).USQL_SHOW_HOST_INFORMATIONβ Set tofalseto prevent displaying database host/version information upon connection. Can also be controlled by theSHOW_HOST_INFORMATIONvariable via\set.USQL_TERM_GRAPHICSβ Force enable or disable terminal graphics support. Values:kitty,iterm,sixel,none. Overrides automatic detection.TERM_GRAPHICSβ Alternative toUSQL_TERM_GRAPHICS.
π₯ EXAMPLES π₯
Connect to a PostgreSQL database interactively:
usql pg://user:pass@localhost:5432/mydatabase
Connect to a local SQLite3 file (will create if not exists if scheme is present):
usql sqlite3://./data.db
Run a single SQL command against a MySQL database and exit:
usql -c SELECT user, host FROM mysql.user; my://root@localhost/
Execute commands from a script file against SQL Server:
usql -f setup.sql ms://sa:Password123@server.example.com/master
Connect using a named connection 'prod_db' defined in config.yaml:
usql prod_db
Set a variable on the command line and use it in a query:
usql -v SCHEMA=public -v TBL=users pg://... -c 'SELECT * FROM :"SCHEMA".:"TBL" LIMIT 10;'
Copy all data from a PostgreSQL table 'source_tbl' to an Oracle table 'TARGET_TBL':
usql -c \copy pg://... or://... 'SELECT * FROM source_tbl' 'TARGET_TBL'
Connect to a CSV file in the current directory and query it:
usql csvq://. -c SELECT column_a, column_b FROM 'data.csv' WHERE column_a > 10;
β SEE ALSO β
The full documentation, source code, and issue tracker can be found on GitHub:
https://github.com/xo/usql
okay that's the whole thing, you're literally so ready. π this was usql 0.19.19, from April 2025, and yes it's the USQL(1) page β go slay some queries, bestie. π«Άβ¨π
π¦ where this page comes from
- ubuntu resolute: usql 0.19.19-0ubuntu1
- ubuntu stonking: usql 0.19.19-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms