Introduction
usql is a universal command-line SQL client inspired by psql. It provides a single binary that connects to PostgreSQL, MySQL, SQLite, SQL Server, Oracle, CockroachDB, and over 40 other database engines using a consistent URL-based connection string format. Instead of installing and learning separate CLI tools for each database, developers use one tool with familiar readline editing, tab completion, and backslash meta-commands across all supported engines.
What usql Does
- Connects to 40+ database engines through a unified URL connection string syntax
- Provides psql-style backslash commands (d, dt, di, l) that work across databases
- Supports readline-based editing with tab completion for tables and columns
- Outputs query results in multiple formats: aligned, CSV, JSON, HTML, and vertical
- Executes SQL scripts from files with variable substitution and conditional logic
Architecture Overview
usql is a single Go binary that dynamically loads database drivers at compile time. Each connection URL scheme (postgres://, mysql://, sqlite://) maps to the appropriate Go database/sql driver. The shell layer wraps the driver with readline support, backslash command parsing, and output formatting. Metadata introspection commands are translated to the appropriate INFORMATION_SCHEMA or catalog queries for each engine.
Self-Hosting & Configuration
- Install a single static binary with no runtime dependencies
- Set
USQL_DSNenvironment variable for a default connection - Configure
.usqlrcfor startup commands, prompt format, and output preferences - Use
copyto import and export CSV data across different database types - Pass
-cfor non-interactive single-command execution in scripts
Key Features
- One binary replaces psql, mysql, sqlite3, sqlcmd, and dozens of other clients
- Consistent backslash commands for schema introspection across all engines
- Copy data between different database types with
copy - Syntax highlighting and auto-completion in the interactive shell
- Supports ODBC and ADODB for connecting to any database with a driver
Comparison with Similar Tools
- psql — PostgreSQL only; usql covers 40+ databases with similar UX
- mycli / pgcli — single-database CLIs with rich auto-complete; usql trades depth for breadth
- DBeaver — full GUI client; usql is terminal-native and scriptable
- dbcli — Python-based per-database CLIs; usql is a single Go binary for all
- DataGrip — commercial IDE; usql is free, lightweight, and shell-friendly
FAQ
Q: Which databases does usql support? A: Over 40 engines including PostgreSQL, MySQL, SQLite, SQL Server, Oracle, CockroachDB, Cassandra, MongoDB, Snowflake, BigQuery, ClickHouse, and more.
Q: Can I use usql in scripts?
A: Yes. Use usql -c "SELECT ..." postgres://... for one-shot queries, or pipe SQL files with usql postgres://... < script.sql.
Q: Does it support SSH tunneling? A: usql itself does not handle SSH tunneling, but you can use standard SSH port forwarding and connect to the forwarded local port.
Q: How do I switch output format?
A: Use pset format csv or pset format json to change the output format within a session.