$linuxjunkies
>

sqlite3(1)

Interactive command-line interface for SQLite databases.

UbuntuDebianFedoraArch

Synopsis

sqlite3 [OPTIONS] [DATABASE_FILE] [SQL_STATEMENTS]

Description

sqlite3 is a command-line tool for creating, querying, and managing SQLite databases. It provides an interactive shell where you can execute SQL commands, inspect database structure, and manage data. SQLite is a lightweight, file-based relational database engine with no separate server process.

When invoked without arguments, sqlite3 opens an interactive prompt. You can also pass a database filename to open a specific database, or pipe SQL commands directly. All data persists in a single file on disk, making SQLite ideal for embedded applications, testing, and small-to-medium projects.

Common options

FlagWhat it does
-init FILERead and execute SQL commands from FILE before starting interactive mode
-batchForce batch I/O mode (exit on first error); useful for scripts
-headerPrint column headers in query results
-columnLeft-align columns and pad output to fit column width
-listSet output mode to list (pipe-separated); the default mode
-separator SEPUse SEP as the output field separator (default is '|' in list mode)
-jsonFormat output as JSON
-cmd SQLExecute SQL statement before starting interactive mode
-bailStop on first error; prevents further command execution
-readonlyOpen database in read-only mode; no modifications allowed

Examples

Open or create the database file 'mydata.db' and enter interactive shell

sqlite3 mydata.db

Execute a single SQL query against the database and exit

sqlite3 mydata.db 'SELECT * FROM users;'

Run a query with column headers and aligned output formatting

sqlite3 -header -column mydata.db 'SELECT id, name, email FROM users;'

Load and execute SQL commands from a file to create tables or load data

sqlite3 mydata.db < schema.sql

Query the database and output results as JSON

sqlite3 -json mydata.db 'SELECT * FROM products LIMIT 5;'

List all tables in the database without entering interactive mode

sqlite3 -cmd '.tables' mydata.db

Export query results as comma-separated values for CSV import

sqlite3 -separator ',' mydata.db 'SELECT * FROM sales;'

Display the CREATE TABLE statement for the 'users' table

sqlite3 mydata.db '.schema users'

Related commands