Skip to the tool workspace
Browser 123

Handleidingen Data and documents

How to open a SQLite file without installing anything

Look inside a .db or .sqlite file: the sqlite3 command your Mac already has, how to read an app's database without changing it, what the -wal file is for, and a viewer for when you can't run a command.

A .sqlite, .sqlite3 or .db file is a whole database in one file: tables, rows, indexes, the lot. Browsers keep their history in one, apps keep their data in one, and developers send them around as test data. Double-clicking does nothing useful, because there is no app for "a database" until you install one. On a Mac you already have one.

The SQLite Database Viewer with the customers table of shop.sqlite open: the Search box, the range 1 to 120 of 120, Add row, the Browse, Query and Schema tabs, and the grid of customers starting with 1, Mallory Quinn

A database someone sent, open in the browser. Nothing is uploaded.

The direct waysqlite3macOS (built in) · Linux

macOS ships sqlite3 (3.51.0 on macOS 26.5). Open the file read-only, so a slip of the keyboard can't change it:

sqlite3 -readonly shop.sqlite

Then, at the sqlite> prompt:

.tables
.mode box
SELECT id, name, city, plan FROM customers LIMIT 5;
customer_totals  customers        orders
┌────┬───────────────────┬────────┬──────┐
│ id │       name        │  city  │ plan │
├────┼───────────────────┼────────┼──────┤
│ 1  │ Mallory Quinn     │ Vienna │ team │
│ 2  │ Katya Okoye       │ Oslo   │ pro  │
│ 3  │ Pavel Vasquez     │ Berlin │ free │
│ 4  │ Viktor Eriksen    │ Lyon   │ team │
│ 5  │ Beatrice Lindgren │ Gdansk │ pro  │
└────┴───────────────────┴────────┴──────┘

.quit leaves. On Debian and Ubuntu, sudo apt install sqlite3 gives you the same command.

Look around with sqlite3

Three dot-commands do most of the work. .tables lists tables and views. .schema shows how a table is built:

sqlite> .schema orders
CREATE TABLE orders (
  id          INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL REFERENCES customers (id),
  total       REAL NOT NULL,
  placed      TEXT NOT NULL,
  status      TEXT NOT NULL
);

And .mode box draws results as a table instead of the default pipe-separated lines. After that it is ordinary SQL:

sqlite> SELECT status, count(*) AS n FROM orders GROUP BY status;
┌───────────┬────┐
│  status   │ n  │
├───────────┼────┤
│ delivered │ 65 │
│ paid      │ 65 │
│ pending   │ 65 │
│ shipped   │ 65 │
└───────────┴────┘

With -readonly, anything that writes is refused and the file is left as it was. We ran DELETE FROM orders; against it to check:

Error: stepping, attempt to write a readonly database (8)

The SHA-1 of shop.sqlite was the same before and after every command in this section.

Save a table as CSV

.once sends the next result to a file instead of the screen:

sqlite> .headers on
sqlite> .mode csv
sqlite> .once customers.csv
sqlite> SELECT id, name, email, city FROM customers;

That wrote customers.csv with a header row and all 120 customers:

id,name,email,city
1,"Mallory Quinn",[email protected],Vienna
2,"Katya Okoye",[email protected],Oslo

.once works with -readonly, because the CSV is a new file, not the database.

An app's database: copy it first

Opening a file that a running program also has open is where things go wrong. Firefox keeps your history in places.sqlite, Chrome in a file called History, and many apps use SQLite for everything. Two things can happen.

The file is locked. Some programs hold the database exclusively while they run. Then every command fails with:

Error: in prepare, database is locked (5)

Quit the program and try again.

The newest changes are in another file. Most apps run SQLite in WAL mode: new changes go into a -wal file next to the database (with a -shm index beside it) and are folded into the main file later. We wrote 5 rows to a WAL database, left 2 of them in the -wal, and copied the files the way you would in Finder:

What was copied Opened with Result
notes.db only sqlite3 -readonly unable to open database file (14)
notes.db only sqlite3 "file:notes.db?immutable=1" 3 rows: the 2 newest are missing
notes.db only plain sqlite3 3 rows, and new -wal and -shm files appear
notes.db + notes.db-wal sqlite3 -readonly 5 rows, main file unchanged
notes.db + notes.db-wal plain sqlite3 5 rows, but the main file is rewritten

So copy the -wal with the database, or better, let SQLite make one self-contained copy. VACUUM INTO reads everything, including what is still in the -wal, and writes a new ordinary database:

sqlite3 -readonly notes.db "VACUUM INTO 'copy.db'"
sqlite3 -readonly copy.db

We ran that while the program still had the database open. copy.db held all 5 rows, it is a single file with no -wal, and the original's checksum and modification time did not change.

If -readonly says unable to open database file

It means the database is in WAL mode and its -shm file isn't there, which a read-only connection can't create. If the program that owns it is closed (so there is no -wal with unsaved changes), read it as it is: sqlite3 "file:notes.db?immutable=1". The same works for the copy: sqlite3 "file:notes.db?immutable=1" "VACUUM INTO 'copy.db'".

Open it in the browser

  1. Open the SQLite Database Viewer and drop the file on the page, or choose Open file(s). Open folder opens every database in a folder. The first visit opens a sample database to try.
  2. Pick a table in the sidebar. Click a column header to sort, use the column menu's Filter by value, or type in Search… to search every column. Click a cell to see its whole value in the side panel.
  3. Query runs any SQL you type; press Run. Results show up to 100,000 rows. Schema shows each table's CREATE statement, its indexes and its triggers.
  4. To change something, double-click a cell, or use the row menu for Duplicate row and Delete row. Undo and redo work while the database is open. Download saves the edited database as a new file.
The Query tab of the SQLite Database Viewer with a SELECT that counts customers per city in the SQL editor, the Run button, a summary of rows and milliseconds, and the results grid with city and customers columns

The Query tab runs any SQL against the open database.

What to know before you rely on it:

  • Your file is never written to. The viewer edits a copy in the browser. Until you download, the sidebar marks the database as changed.
  • It opens only the main file. Drop the -wal with it and you get a warning that changes still in the -wal are missing. To include them, make a copy with VACUUM INTO as above and open that.
  • The whole file is held in memory. You get a warning from 300 MB, and the limit is about 1 GB; your device may stop sooner.
  • No CSV export. It downloads the database and copies a single row as JSON. For CSV, use sqlite3 as above.
  • Encrypted databases (SQLCipher) don't open, and tables that need the FTS5 or R*Tree extensions open read-only, because the bundled SQLite (3.49.1) doesn't include them.
The SQLite Database Viewer after opening a.sqlite together with a.sqlite-wal: a notice reads a.sqlite has a write-ahead log next to it, and says changes still in the -wal file are not included

The viewer says when a -wal file came with the database.

On Windows: DB Browser for SQLite

Windows has no sqlite3 command. If you want a desktop app, DB Browser for SQLite (3.13.1) is free and open source. Next to the installer, its download page offers a .zip (no installer) and a PortableApp, which are the ones to try on a laptop where you can't install software. There is no portable build for ARM64 Windows. On a Mac it is brew install db-browser-for-sqlite. We did not test it on Windows. Use its read-only open option on an app's database, for the same reasons as above.

If you'd rather have the command, sqlite.org offers it as Command-line tools for Windows x64, a zip from its download page; it runs without installing.

Which to use

  • On a Mac or Linux: sqlite3 -readonly file.db. It is already there, and .once gets you a CSV.
  • An app's live database: VACUUM INTO a copy first, then open the copy with anything.
  • Windows, a managed laptop, a phone, or one quick look: the SQLite Database Viewer. Nothing to install, and nothing leaves the device.
  • Editing and handing it back: the viewer, then Download, and send the new file. The original stays as it was.

Questions people ask

Is a .db file always SQLite?

No. .db is used by many unrelated formats (Windows thumbnail caches, for one). Look at the first 16 bytes: a SQLite database starts with the text SQLite format 3. The viewer checks exactly that and tells you when a file is a CSV, a JSON file, a SQL dump or something it can't read, whatever the extension says.

sqlite3 says "unable to open database file" but the file is right there. Why?

The database is in WAL mode, and a read-only connection can't create the -shm file WAL needs. Open it with the immutable URI instead, sqlite3 "file:app.db?immutable=1", which reads only the main file. If a -wal file sits next to it, make a copy with VACUUM INTO first, or the newest changes are missing.

What are the -wal and -shm files next to the database?

The write-ahead log and its index. In WAL mode SQLite writes new changes to the -wal file first and folds them into the main file later. Until then, the main file on its own is out of date: in our test it showed 3 rows of 5. Copy the -wal along with the database, or let sqlite3 make a single-file copy with VACUUM INTO.

Can I edit the database in the browser?

Yes, a copy of it. Double-click a cell to edit it, or run UPDATE and DELETE in the Query tab, which asks before anything that touches many rows. The file you opened is never written to; Download saves the edited copy as a new file.

How do I get a table out as CSV?

With sqlite3: .headers on, .mode csv, .once customers.csv, then your SELECT. DB Browser for SQLite exports tables to CSV too. The browser viewer has no CSV export: it downloads the database, and copies a single row as JSON.

Tools in deze handleiding

Alles draait op je apparaat

Alle handleidingen

/
123 items
Draait in je browser·Je bestanden blijven op dit apparaat
Out0 B
Ready—