SQLite is a small, lightweight SQL database manager. it is a free, cross-platform database management system. It is famous for its efficiency and ability to interface with many different programming languages. SQLite is a useful tool for database management. One can quickly create a database and manipulate it with various commands.
In this article, you will install SQLite on Ubuntu then create a database, and read data from it.
Note: the installation guide of this article supports all the versions of the Ubuntu server.
- A root or non-root user with
Installing SQLlite on ubuntu:
- Update the software repository before installing the SQLite package.
$ sudo apt update
- Install the latest and stable version of SQLite using execute the below command.
$ sudo apt install sqlite -y
- Verify the successful completion of the SQLite by checking the installed version.
$ sqlite3 --version
Create and use SQLite database:
- SQLite database is stored as a file, we can create an SQLite database using the
Above command will create a testdb database If the file testdb.db already exists, SQLite will open a connection to it if it does not exist, SQLite will create it.
$ sqlite3 testdb.db
- Use the following command to create the table.
CREATE TABLE table_name(id integer NOT NULL, name text NOT NULL, length integer NOT NULL);
- After creating the table, an empty prompt will return. Now let’s insert some values into it.
INSERT INTO table_name VALUES (1, "test1",100);
- We can use the select command To view the table with all of the inserted values.
SELECT * FROM table_name;
- Type the below command to exit from the sqllite3 terminal.