Join my Laravel for REST API's course on Udemy 👀

Open a SQLite database in the terminal

March 27, 2021  ‐ 2 min read

SQLite databases are quite convenient in web development, when prototyping a simple website for example. It comes as the default database for a couple big web frameworks like Ruby on Rails and Django. Mind that none of them also encourage you to use SQLite in production.

There are graphical database browsers available for SQLite, but you can open a SQLite database in the terminal as well. To open a SQLite database in shell mode you enter the sqlite3 command followed by the path to your database file.

$ sqlite3 db.sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite>

You can now run SQL queries from the SQLite shell. Besides that there are many commands available, all starting with a period(.). One of those commands is actually mentioned when you open the shell: .help. When you run this .help command you will see a list of available commands in the SQLite shell.

A couple useful SQLite shell commands are:

CommandDescription
.databasesList names and files of attached databases
.dumpDump the database in a SQL text format
.excelDisplay the output of next command in spreadsheet
.exitExit this program
.helpShow a list of available commands
.save FILEWrite in-memory database into FILE
.schemaShow the CREATE statements
.tablesList names of tables