# usql — Universal Command-Line SQL Client for Every Database > A universal command-line interface for PostgreSQL, MySQL, SQLite, Oracle, SQL Server, and 40+ other databases with auto-completion and consistent syntax. ## Install Save in your project root: # usql — Universal Command-Line SQL Client for Every Database ## Quick Use ```bash # Install via Go go install github.com/xo/usql@latest # Or via Homebrew brew install xo/xo/usql # Connect to PostgreSQL usql postgres://user:pass@localhost/mydb # Connect to MySQL usql mysql://user:pass@localhost/mydb # Connect to SQLite usql sqlite:///path/to/db.sqlite3 ``` ## 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_DSN` environment variable for a default connection - Configure `.usqlrc` for startup commands, prompt format, and output preferences - Use `copy` to import and export CSV data across different database types - Pass `-c` for 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. ## Sources - https://github.com/xo/usql - https://github.com/xo/usql#database-support --- Source: https://tokrepo.com/en/workflows/bac4c91b-3d5a-11f1-9bc6-00163e2b0d79 Author: AI Open Source