Open and run
sqlite3 <file.db>
Open (or create) a database
sqlite3 <file.db> "<sql>"
Run one statement and exit
sqlite3 <file.db> < <script.sql>
Run a SQL script
.read <script.sql>
Run a script from inside the shell
.open <file.db>
Switch to another database file
--new wipes an existing file without asking
sqlite3 -readonly <file.db>
Open without write access
.help
List all dot-commands
.shell <cmd>
Run a shell command
.cd <dir>
Change working directory
sqlite3 -bail -batch <file.db>
Stop at the first error
sqlite3 -safe <file.db>
Disable file access and shell escapes
Not a full sandbox
sqlite3 -init <file>
Run a startup script first
.timeout <ms>
Wait for a locked database
Inspect schema
.tables
List tables and views
.tables <pattern>
Filter with a LIKE pattern
.schema
All CREATE statements
.schema <table>
CREATE statements for one table
.schema --indent
Pretty-printed schema
.indexes <table>
List indexes
.databases
Attached databases and files
.dbinfo
Page size, counts, schema cookie
.fullschema
Schema plus sqlite_stat data
Statistics may expose sampled data values
.lint fkey-indexes
Foreign keys lacking an index
.expert
Suggest indexes for next query
Experimental
pragma table_info(<table>);
Columns and types
Import and export
.import --csv <file> <table>
Load CSV into a table
A missing table is created from the header row
.import --csv --skip 1 <file> <table>
Load into an existing table
Without --skip the header becomes a data row
.once <file>
Send next result to a file
.output <file>
Send all results to a file
.once | <cmd>
Pipe next result to a command
.once -x
Open next result in a spreadsheet
select readfile('<path>');
Read a file as a value
select writefile('<path>',
<blob>);
Write a value to a file
.print <text>
Print a literal line
Backup and recover
.backup <file>
Binary copy of main database
Overwrites an existing file silently
.restore <file>
Load a backup into this database
.save <file>
Write database to a file
.dump
Whole database as SQL text
.dump <table>
One table as SQL text
sqlite3 <old.db> .dump | sqlite3 <new.db>
Rebuild into a fresh file
.recover
Salvage data from a corrupt file
Orphaned rows land in lost_and_found
.clone <newdb>
Copy content into a new file
.sha3sum
Hash of database content
pragma integrity_check;
Check for corruption