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 CSV with mode and separator
.mode csv
.import ./users.csv users

# Set shell parsing options before import.

Export a query result to CSV
.headers on
.mode csv
.once recent_users.csv
SELECT id, email, created_at FROM users ORDER BY created_at DESC LIMIT 100;

# Write selected rows to a CSV file.

Dump one table
.dump users

# Export only selected table schema and data.

Load data from an SQL file
sqlite3 app.db < seed.sql

# Execute inserts and DDL from a seed script.

## Backup and maintenance
Create a compact backup with VACUUM INTO
VACUUM INTO 'backup-2026-03-28.db';

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

Use the shell backup command
.backup backup.db

# Create a backup from inside sqlite3.

Run VACUUM
VACUUM;

# Rebuild the database file and reclaim free space.

Run an integrity check
PRAGMA integrity_check;

# Verify the database structure and content consistency.

Recommended next

No recommendations yet.