sqlite3(1)
Interactive command-line interface for SQLite databases.
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
| Flag | What it does |
|---|---|
-init FILE | Read and execute SQL commands from FILE before starting interactive mode |
-batch | Force batch I/O mode (exit on first error); useful for scripts |
-header | Print column headers in query results |
-column | Left-align columns and pad output to fit column width |
-list | Set output mode to list (pipe-separated); the default mode |
-separator SEP | Use SEP as the output field separator (default is '|' in list mode) |
-json | Format output as JSON |
-cmd SQL | Execute SQL statement before starting interactive mode |
-bail | Stop on first error; prevents further command execution |
-readonly | Open database in read-only mode; no modifications allowed |
Examples
Open or create the database file 'mydata.db' and enter interactive shell
sqlite3 mydata.dbExecute 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.sqlQuery 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.dbExport 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'