SQLite Import, Export, and Backup Cheatsheet

CSV import/export, SQL dumps, VACUUM INTO, backup copies, and repeatable data movement patterns for SQLite databases.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Move data in and out

Import files, export query results, and create SQL dumps.

Import CSV with mode and separator

Set shell parsing options before import.

textANYsqlite3csvimport
text
.mode csv
.import ./users.csv users
Notes

A reliable shell pattern when loading CSV into an existing table.

Export a query result to CSV

Write selected rows to a CSV file.

textANYsqlite3csvexport
text
.headers on
.mode csv
.once recent_users.csv
SELECT id, email, created_at FROM users ORDER BY created_at DESC LIMIT 100;
Notes

Good for ad hoc reporting and support workflows.

Dump one table

Export only selected table schema and data.

textANYsqlite3dumptable
text
.dump users
Notes

Useful when sharing a fixture or moving just one logical dataset.

Load data from an SQL file

Execute inserts and DDL from a seed script.

bashANYsqliteseedshell
bash
sqlite3 app.db < seed.sql
Notes

A shell-friendly way to initialize or refresh a local database.

Backup and maintenance

Create safe copies and compact files.

Create a compact backup with VACUUM INTO

Write a fresh copy of the database to a new file.

sqlANYsqlitevacuum intobackup
sql
VACUUM INTO 'backup-2026-03-28.db';
Notes

Produces a compact copy and is a strong option for backup-style snapshots.

Use the shell backup command

Create a backup from inside sqlite3.

textANYsqlite3backup
text
.backup backup.db
Notes

A convenient shell-level backup path for local workflows.

Run VACUUM

Rebuild the database file and reclaim free space.

sqlANYsqlitevacuummaintenance
sql
VACUUM;
Notes

Can reduce file size after large deletes or schema churn.

Run an integrity check

Verify the database structure and content consistency.

sqlANYsqliteintegrity_checkhealth
sql
PRAGMA integrity_check;
Notes

Useful before and after migrations, backup jobs, or corruption investigations.

Recommended next

No recommendations yet.