Guide
How to open a .db file
Published
A .db file is a database file, but the extension alone doesn’t say which kind. Most of the time it’s SQLite, the small file-based database used by phones, browsers, desktop apps and countless side projects. This guide shows how to check, then three ways to open one: in your browser, in a desktop app, or from the command line.
Check that it’s a SQLite file
Every SQLite 3 database starts with the same 16 bytes: the text SQLite format 3 followed by a zero byte. You can check it in a few seconds:
- Any computer: open the file in a plain text editor (Notepad, TextEdit). If the very first characters are
SQLite format 3, it’s SQLite. Close the editor without saving. - Mac or Linux terminal: the
filecommand recognises it.
file mydata.db
# mydata.db: SQLite 3.x database, ...
- Or just try it: OpenSQLite checks the header before opening anything and tells you plainly if the file isn’t a SQLite database.
Some common .db files are not SQLite:
| File | What it is |
|---|---|
Thumbs.db |
Windows thumbnail cache. Safe to ignore; not a database you can browse. |
Paradox .db |
Tables from the old Borland Paradox database. |
Berkeley DB .db |
A key-value store used by some older Unix software. |
If your file isn’t SQLite, find out which app created it. That app (or its documentation) is usually the only reliable way to read it.
Option 1: Open it in your browser
The quickest way, with nothing to install:
- Go to opensqlite.com.
- Drag the file onto the drop zone, or click Open SQLite file and pick it.
- Choose a table from the list to see its rows. Click a column name to sort, use the search box to filter rows, and click a row to see every field in full.
The file is opened by SQLite running inside your browser. It’s never uploaded: you can load the page, go offline and it still works. The viewer is read-only, so it can’t change your file. It works on phones too: tap Open SQLite file and pick the database from your Files app.
If your file has a different extension, or none at all, drag it onto the drop zone instead of using the file picker. Any valid SQLite file opens, whatever it’s called.
Option 2: DB Browser for SQLite (desktop app)
DB Browser for SQLite is a free, open-source app for Windows, macOS and Linux. Use it when you need more than browsing: running SQL queries, editing data, changing the schema or exporting to CSV.
- Install it from the website (or see the Mac and Windows guides for one-line installs).
- Choose Open Database Read Only from the File menu if you only want to look. This protects the file from accidental edits.
- Use the Browse Data tab to view tables and Execute SQL to run queries.
Option 3: The sqlite3 command-line tool
The official sqlite3 shell is preinstalled on macOS and most Linux distributions; on Windows it’s a quick install (see the Windows guide). Open the file read-only so nothing can change it:
sqlite3 -readonly mydata.db
Then, at the sqlite> prompt:
.tables
.schema Track
.mode box
SELECT * FROM Track LIMIT 10;
.quit
In order: list the tables, show how the Track table is defined, draw results as a neat table, show the first 10 rows, and exit. (Track is a table in the Chinook sample database; use your own table names.) Commands that start with a dot are shell commands; everything else is SQL and ends with a semicolon.
Common problems
“File is not a database” or “file is encrypted” Either the file isn’t SQLite (see the check above) or it’s encrypted, typically with SQLCipher, which encrypts the header too. An encrypted database can only be opened with its key, in a tool that supports SQLCipher, such as DB Browser for SQLite. OpenSQLite detects files that look encrypted and says so.
“Database is locked” Another program has the database open and is writing to it. Close that program, or copy the file and open the copy.
Recent data seems to be missing
Look for files next to your database with the same name plus -wal or -shm, such as mydata.db-wal. In WAL mode, SQLite keeps recent changes in the -wal file until they’re merged into the main file. Close the app that uses the database (it normally merges the changes on exit), or copy all the files together. See .db vs .sqlite vs .sqlite3 for what each companion file does.
The file is very large
Browser-based viewers hold the whole file in memory, so the limit is your device’s memory. Files of a few hundred megabytes open on most laptops. For multi-gigabyte files, the sqlite3 shell or DB Browser for SQLite read from disk and cope better.
Which should you use?
- Just want to look inside? Use your browser: nothing to install, and the file stays on your device.
- Need to edit or query? Install DB Browser for SQLite.
- Comfortable in a terminal, or scripting? Use
sqlite3.