Skip to content
Latchkey

usql: One CLI for Many SQL Databases

usql <url> -c "SQL" runs a statement against any supported database using one psql-style client.

usql is a single client that talks to Postgres, MySQL, SQL Server, SQLite, CockroachDB, and others through connection URLs. In a polyglot CI pipeline it means one tool and one flag set (-c, -f, backslash commands) across every database.

What it does

usql dispatches to the right driver based on the URL scheme (postgres://, mysql://, sqlserver://, sqlite3:, etc.) and gives a psql-like shell with -c for one command, -f for a file, and familiar backslash meta-commands. It is a Go binary with no per-database client to install.

Common usage

Terminal
# Postgres and MySQL through one tool
usql "postgres://app:secret@db/appdb" -c "SELECT 1"
usql "mysql://app:secret@db/appdb" -c "SHOW TABLES"
# SQLite file and a script file
usql "sqlite3:app.db" -c ".tables"
usql "postgres://app:secret@db/appdb" -f migrate.sql

Options

ItemWhat it does
<scheme>://...Connection URL selecting the database driver
-c "<sql>"Run one command and exit
-f <file>Run SQL from a file
\dt / \dpsql-style meta-commands (where supported)
-w / --no-passwordNever prompt for a password

In CI

usql shines when one pipeline touches several database engines: install one binary instead of psql, mysql, and sqlcmd separately. The URL scheme picks the driver, so double-check it (postgres:// vs mysql://). Pass -w so a missing password fails fast instead of prompting and hanging the job.

Common errors in CI

"unknown driver \"...\" (did you forget to include the tag while building?)" means usql was built without that database driver; install a build that includes it. "connection refused" and "password authentication failed" surface from the underlying driver just as with the native client. A malformed URL scheme routes to the wrong driver, producing a confusing protocol error rather than a clear one.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →