Usql
Universal command-line interface for SQL databases
Install / Use
/learn @xo/UsqlREADME
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.
Installing
usql can be installed via Release, via Homebrew, via AUR, via
Scoop, via Go, or via Docker:
Installing via Release
- Download a release for your platform
- Extract the
usqlorusql.exefile from the.tar.bz2or.zipfile - Move the extracted executable to somewhere on your
$PATH(Linux/macOS) or%PATH%(Windows)
Installing via Homebrew (macOS and Linux)
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
Installing via AUR (Arch Linux)
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...
...
Installing via Scoop (Windows)
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
Installing via Go
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.
Installing via Docker
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
Building
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@main
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@main
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@main
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@main
# build/install all drivers (includes CGO drivers and problematic drivers)
$ go install -tags all github.com/xo/usql@main
Database Support
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.
Supported Database Schemes and Aliases
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] <sup>[†][f-cgo]</sup> |
| ClickH
Related Skills
oracle
344.4kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
xurl
344.4kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
prose
344.4kOpenProse VM skill pack. Activate on any `prose` command, .prose files, or OpenProse mentions; orchestrates multi-agent workflows.
Command Development
99.2kThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
