2025-03-14 21:59:59 -06:00
|
|
|
# usql
|
|
|
|
|
|
|
|
|
|
> Universal CLI interface for SQL databases.
|
2026-02-18 06:55:01 -07:00
|
|
|
> More information: <https://github.com/xo/usql#using>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Connect to a specific database:
|
|
|
|
|
|
|
|
|
|
`usql {{sqlserver|mysql|postgres|sqlite3|...}}://{{username}}:{{password}}@{{host}}:{{port}}/{{database_name}}`
|
|
|
|
|
|
|
|
|
|
- Execute commands from a file:
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`usql {{[-f|--file]}} {{path/to/query.sql}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Execute a specific SQL command:
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`usql {{[-c|--command]}} "{{sql_command}}"`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- [Interactive] Run an SQL command in the `usql` prompt:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`{{command}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- [Interactive] Display the database schema:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`\d`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- [Interactive] Export query results to a specific file:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`\g {{path/to/file_with_results}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- [Interactive] Import data from a CSV file into a specific table:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`\copy {{path/to/data.csv}} {{table_name}}`
|