LinuxCommandLibrary

usql

Universal CLI interface for SQL databases.

TLDR

Connect to a specific database

$ usql [sqlserver|mysql|postgres|sqlite3|...]://[username]:[password]@[host]:[port]/[database_name]
copy


Execute commands from a file
$ usql --file=[path/to/query.sql]
copy


Execute a specific SQL command
$ usql --command="[sql_command]"
copy


Run an SQL command in the usql prompt
$ [prompt]=> [command]
copy


Display the database schema
$ [prompt]=> \d
copy


Export query results to a specific file
$ [prompt]=> \g [path/to/file_with_results]
copy


Import data from a CSV file into a specific table
$ [prompt]=> \copy [path/to/data.csv] [table_name]
copy

Copied to clipboard