Linux command
usql 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Connect to PostgreSQL
usql postgres://[user]:[pass]@[host]/[database]
Connect to MySQL
usql mysql://[user]:[pass]@[host]/[database]
Connect to SQLite
usql sqlite:[database.db]
Execute query
usql [connection_url] -c "[SELECT * FROM table]"
Execute file
usql [connection_url] -f [script.sql]
List databases
usql [connection_url] -c "\\l"
Describe table
usql [connection_url] -c "\\d [table_name]"
说明
usql is a universal command-line interface for SQL databases. It connects to PostgreSQL, MySQL, SQLite, SQL Server, Oracle, and many other databases (including NoSQL databases) with a consistent psql-inspired interface. Connection strings follow URL format. The scheme identifies the database type: postgres://, mysql://, sqlite:, mssql://, oracle://, etc. When no scheme is given, usql auto-detects: directories use PostgreSQL, regular files use SQLite3 or DuckDB. Backslash commands work across databases: \\l lists databases, \\dt lists tables, \\d describes objects, \\drivers lists available database drivers. Query output can be formatted as tables, CSV, JSON, or other formats. Tab completion assists with table and column names, and history persists across sessions.
参数
- -c _CMD_
- Execute command and exit.
- -f _FILE_
- Execute file.
- -o _FILE_
- Output to file.
- -w, --no-password
- Never prompt for password.
- -W, --password
- Always prompt for password.
- -X, --no-rc
- Don't read rc file.
- -t, --tuples-only
- Only print rows.
- -q, --quiet
- Quiet mode.
- -v _NAME=VALUE_
- Set variable.
- --help
- Show help.
- --version
- Show version.
FAQ
What is the usql command used for?
usql is a universal command-line interface for SQL databases. It connects to PostgreSQL, MySQL, SQLite, SQL Server, Oracle, and many other databases (including NoSQL databases) with a consistent psql-inspired interface. Connection strings follow URL format. The scheme identifies the database type: postgres://, mysql://, sqlite:, mssql://, oracle://, etc. When no scheme is given, usql auto-detects: directories use PostgreSQL, regular files use SQLite3 or DuckDB. Backslash commands work across databases: \\l lists databases, \\dt lists tables, \\d describes objects, \\drivers lists available database drivers. Query output can be formatted as tables, CSV, JSON, or other formats. Tab completion assists with table and column names, and history persists across sessions.
How do I run a basic usql example?
Run `usql postgres://[user]:[pass]@[host]/[database]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c _CMD_ do in usql?
Execute command and exit.