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:
Command | Description |
---|---|
.databases | List names and files of attached databases |
.dump | Dump the database in a SQL text format |
.excel | Display the output of next command in spreadsheet |
.exit | Exit this program |
.help | Show a list of available commands |
.save FILE | Write in-memory database into FILE |
.schema | Show the CREATE statements |
.tables | List names of tables |