sqlite3 the SQLite command-line shell

sqlite3 is the official interactive shell for SQLite databases. sqx writes ordinary SQLite files with import and -save, so you can open them in sqlite3 for interactive work, backups or schema changes.

Availability Preinstalled on macOS and many Linux distributions; otherwise apt install sqlite3 or brew install sqlite

Syntax

sqlite3 [options] [database] [sql]

Common options

OptionWhat it does
.tablesList tables (inside the shell)
.schema [table]Show CREATE statements
.mode csv / .mode tableChange the output format
.headers onPrint column names
-csv -headerCommand-line equivalents for one-off queries

Examples

Open a database interactively

sqlite3 project.db

List tables from the shell

sqlite3 project.db .tables

One-off query as CSV

sqlite3 -csv -header project.db "SELECT * FROM users LIMIT 5"

Use sqlite3 with sqx

Build a database with sqx, explore it with sqlite3

sqx import -db project.db -t users users.csv
sqlite3 project.db "SELECT plan, COUNT(*) FROM users GROUP BY plan"

sqx's extra functions, such as http_status or html_title, exist only inside sqx. Run those queries with sqx -db project.db, and use sqlite3 for plain SQL.

Full documentation

This page covers the essentials. For every option, see the official documentation:

Or read the manual in your terminal: man sqlite3