
Installing | Building | Database Support | Using | Features and Compatibility | Releases | Contributing
usql is a universal command-line interface for PostgreSQL, MySQL, Oracle
Database, SQLite3, Microsoft SQL Server, and many other databases
including NoSQL and non-relational databases!
usql provides a simple way to work with SQL and NoSQL databases
via a command-line inspired by PostgreSQL's psql. usql supports most of the
core psql features, such as [variables][variables], [backticks][backticks],
[backslash commands][commands] and has additional features that psql does
not, such as multiple database support, [copying between databases][copying],
[syntax highlighting][highlighting], [context-based completion][completion],
and [terminal graphics][termgraphics].
Database administrators and developers that would prefer to work with a tool
like psql with non-PostgreSQL databases, will find usql intuitive,
easy-to-use, and a great replacement for the command-line clients/tools
for other databases.
usql can be installed via Release, via Homebrew, via AUR, via
Scoop, via Go, or via Docker:
usql or usql.exe file from the .tar.bz2 or .zip file$PATH (Linux/macOS) or
%PATH% (Windows)Install usql from the [xo/xo tap][xo-tap] in the usual way with the [brew
command][homebrew]:
# install usql with most drivers
$ brew install xo/xo/usql
Support for ODBC databases is available through the --with-odbc
install flag:
# add xo tap
$ brew tap xo/xo
# install usql with odbc support
$ brew install --with-odbc usql
Install usql from the [Arch Linux AUR][aur] in the usual way with the [yay
command][yay]:
# install usql with most drivers
$ yay -S usql
Alternately, build and [install using makepkg][arch-makepkg]:
$ git clone https://aur.archlinux.org/usql.git && cd usql
$ makepkg -si
==> Making package: usql 0.12.10-1 (Fri 26 Aug 2022 05:56:09 AM WIB)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
-> Downloading usql-0.12.10.tar.gz...
...
Install usql using Scoop:
# Optional: Needed to run a remote script the first time
> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# install scoop if not already installed
> irm get.scoop.sh | iex
# install usql with scoop
> scoop install usql
Install usql in the usual Go fashion:
# install latest usql version with base drivers
$ go install github.com/xo/usql@latest
# alternately, install usql with most drivers (see below for info about build tags)
$ go install -tags most github.com/xo/usql@latest
See below for information on usql build tags.
An official container image (docker.io/usql/usql) is maintained
by the usql team, and can be used with Docker, Podman, or other container
runtime.
Install usql with Docker, Podman, or other container runtime:
# run interactive shell and mount the $PWD/data directory as a volume for use
# within the container
$ docker run --rm -it --volume $(pwd)/data:/data docker.io/usql/usql:latest sqlite3://data/test.db
Trying to pull docker.io/usql/usql:latest...
Getting image source signatures
Copying blob af48168d69d8 done |
Copying blob efc2b5ad9eec skipped: already exists
Copying config 917ceb411d done |
Writing manifest to image destination
Connected with driver sqlite3 (SQLite3 3.45.1)
Type "help" for help.
sq:data/test.db=> \q
# run postgres locally
$ docker run --detach --rm --name=postgres --publish=5432:5432 --env=POSTGRES_PASSWORD=P4ssw0rd docker.io/usql/postgres
# connect to local postgres instance
$ docker run --rm --network host -it docker.io/usql/usql:latest postgres://postgres:P4ssw0rd@localhost
Connected with driver postgres (PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1))
Type "help" for help.
pg:postgres@localhost=> \q
# run specific usql version
$ docker run --rm -it docker.io/usql/usql:0.19.3
When building usql out-of-the-box with go build or go install, only the
base drivers for PostgreSQL, MySQL, SQLite3, Microsoft SQL
Server, Oracle, CSVQ will be included in the build:
# build/install with base drivers (PostgreSQL, MySQL, SQLite3, Microsoft SQL Server,
# Oracle, CSVQ)
$ go install github.com/xo/usql@master
Other databases can be enabled by specifying the build tag for their database driver.
# build/install with base, Avatica, and ODBC drivers
$ go install -tags 'avatica odbc' github.com/xo/usql@master
For every build tag <driver>, there is also a no_<driver> build tag
that will disable the driver:
# build/install most drivers, excluding Avatica, Couchbase, and PostgreSQL
$ go install -tags 'most no_avatica no_couchbase no_postgres' github.com/xo/usql@master
By specifying the build tags most or all, the build will include most, and
all SQL drivers, respectively:
# build/install with most drivers (excludes CGO drivers and problematic drivers)
$ go install -tags most github.com/xo/usql@master
# build/install all drivers (includes CGO drivers and problematic drivers)
$ go install -tags all github.com/xo/usql@master
usql works with all Go standard library compatible SQL drivers supported by
[github.com/xo/dburl][dburl].
The list of drivers that usql was built with can be displayed with the
[\drivers command][commands]:
$ cd $GOPATH/src/github.com/xo/usql
# build excluding the base drivers, and including cassandra and moderncsqlite
$ go build -tags 'no_postgres no_oracle no_sqlserver no_sqlite3 cassandra moderncsqlite'
# show built driver support
$ ./usql -c '\drivers'
Available Drivers:
cql [ca, scy, scylla, datastax, cassandra]
memsql (mysql) [me]
moderncsqlite [mq, sq, file, sqlite, sqlite3, modernsqlite]
mysql [my, maria, aurora, mariadb, percona]
tidb (mysql) [ti]
vitess (mysql) [vt]
The above shows that usql was built with only the mysql, cassandra (ie,
cql), and moderncsqlite drivers. The output above reflects information
about the drivers available to usql, specifically the internal driver name,
its primary URL scheme, the driver's available scheme aliases (shown in
[...]), and the real/underlying driver (shown in (...)) for wire compatible
drivers.
The following are the [Go SQL drivers][go-sql] that usql supports, the
associated database, scheme / build tag, and scheme aliases:
| Database | Scheme / Tag | Scheme Aliases | Driver Package / Notes |
|---|---|---|---|
| PostgreSQL | postgres |
pg, pgsql, postgresql |
[github.com/lib/pq][d-postgres] |
| MySQL | mysql |
my, maria, aurora, mariadb, percona |
[github.com/go-sql-driver/mysql][d-mysql] |
| Microsoft SQL Server | sqlserver |
ms, mssql, azuresql |
[github.com/microsoft/go-mssqldb][d-sqlserver] |
| Oracle Database | oracle |
or, ora, oci, oci8, odpi, odpi-c |
[github.com/sijms/go-ora/v2][d-oracle] |
| SQLite3 | sqlite3 |
sq, sqlite, file |
[github.com/mattn/go-sqlite3][d-sqlite3] [†][f-cgo] |
| ClickHouse | clickhouse |
ch |
[github.com/ClickHouse/clickhouse-go/v2][d-clickhouse] |
| CSVQ | csvq |
cs, csv, tsv, json |
[github.com/mithrandie/csvq-driver][d-csvq] |
| Alibaba MaxCompute | maxcompute |
mc |
[sqlflow.org/gomaxcompute][d-maxcompute] |
| Alibaba Tablestore | ots |
ot, tablestore |
[github.com/aliyun/aliyun-tablestore-go-sql-driver][d-ots] |
| Apache Avatica | avatica |
av, phoenix |
[github.com/apache/calcite-avatica-go/v5][d-avatica] |
| Apache H2 | h2 |
[github.com/jmrobles/h2go][d-h2] | |
| Apache Hive | hive |
hi, hive2 |
[sqlflow.org/gohive][d-hive] |
| Apache Ignite | ignite |
ig, gridgain |
[github.com/amsokol/ignite-go-client/sql][d-ignite] |
| Apache Impala | impala |
im |
[github.com/sclgo/impala-go][d-impala] |
| AWS Athena | athena |
s3, aws, awsathena |
[github.com/uber/athenadriver/go][d-athena] |
| Azure CosmosDB | cosmos |
cm, gocosmos |
[github.com/btnguyen2k/gocosmos][d-cosmos] |
| Cassandra | cassandra |
ca, scy, scylla, datastax, cql |
[github.com/MichaelS11/go-cql-driver][d-cassandra] |
| ChaiSQL | chai |
ci, genji, chaisql |
[github.com/chaisql/chai][d-chai] |
| Couchbase | couchbase |
n1, n1ql |
[github.com/couchbase/go_n1ql][d-couchbase] |
| Cznic QL | ql |
cznic, cznicql |
[modernc.org/ql][d-ql] |
| Databend | databend |
dd, bend |
[github.com/datafuselabs/databend-go][d-databend] |
| Databricks | databricks |
br, brick, bricks, databrick |
[github.com/databricks/databricks-sql-go][d-databricks] |
| DuckDB | duckdb |
dk, ddb, duck, file |
[github.com/duckdb/duckdb-go/v2][d-duckdb] [†][f-cgo] |
| DynamoDb | dynamodb |
dy, dyn, dynamo, dynamodb |
[github.com/btnguyen2k/godynamo][d-dynamodb] |
| Exasol | exasol |
ex, exa |
[github.com/exasol/exasol-driver-go][d-exasol] |
| Firebird | firebird |
fb, firebirdsql |
[github.com/nakagami/firebirdsql][d-firebird] |
| FlightSQL | flightsql |
fl, flight |
[github.com/apache/arrow/go/v17/arrow/flight/flightsql/driver][d-flightsql] |
| Google BigQuery | bigquery |
bq |