~/SQLite CLI Essential Commands

Feb 15, 2021


The SQLite CLI lets you manage databases directly from your terminal. Here are the main commands to use.

Starting the CLI
Start by running:

1
sqlite3 mydatabase.db

Viewing Tables
List all tables:

1
.tables

Schema Information
See the schema of a table:

1
.schema tablename

Running SQL Queries
Example of a typical query:

1
SELECT * FROM tablename;

Import Data
Import CSV data:

1
2
.mode csv
.import mydata.csv tablename

Export Data
Export results to a file:

1
2
3
.output output.txt
SELECT * FROM tablename;
.output stdout

Exiting the SQLite CLI
Exit with:

1
.exit

or

1
.quit

Read more in the official SQLite documentation.

Tags: [sqlite] [cli]