We have often heard of MySQL, MariaDB, and PostgreSQL, but not about SQLite. SQLite is a small, lightweight, yet powerful SQL Database Manager. In this post, we will learn all about what SQLite is and how we can install SQLite on CentOS 8 operating system.

SQLite does not run as a system service like other DBMS. So, it is known as a self-contained database manager that does not work like other DBMS, such as MySQL, PostgreSQL, and MariaDB.

SQLite is built based on the C language to make it an efficient and fast database management system. Its binaries in all significant operating systems are available like Windows, Linux, and macOS, so it is a multi-platform and open-source application.

Installation of SQLite on CentOS 8

SQLite is available in the default package manager of the CentOS 8 operating system and easily downloadable and installable from there.

But before that, it is an excellent practice to make sure that your system is up-to-date. To upgrade the installed packages and dependencies, execute the command typed below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/1.jpg" data-lazy- height="134" src="data:image/svg xml,” width=”713″>

After upgrading, make sure that the epel-release is enabled as well on your CentOS 8 operating system. If it is not enabled, you can execute the command below to enable the epel-release:

$ sudo dnf install epel-release

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/2.jpg" data-lazy- height="132" src="data:image/svg xml,” width=”715″>

Once the epel-release is enabled, execute the upgrade command once again to make the packages up-to-date:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/3.jpg" data-lazy- height="113" src="data:image/svg xml,” width=”720″>

Once the system is up-to-date and ready, we can install SQLite on CentOS 8 by executing the single command.

For installing the latest and stable version of SQLite from the DNF package manager, execute the command:

$ sudo dnf install sqlite

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/4.jpg" data-lazy- height="131" src="data:image/svg xml,” width=”717″>

SQLite will be downloaded and installed in a few moments.

Once the installation of SQLite on CentOS 8 is completed, you can confirm the installation by executing the command given below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/5.jpg" data-lazy- height="80" src="data:image/svg xml,” width=”725″>

It is verified that SQLite’s version 3.26 is successfully installed on CentOS 8 operating system. Now, let’s get started with SQLite in CentOS 8 and learn about its primary usage.

Getting Started With SQLite on CentOS 8

For getting started with SQLite on CentOS 8, simply execute the “sqlite3” command in the terminal of CentOS 8 to get into the shell of SQLite:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/6.jpg" data-lazy- height="113" src="data:image/svg xml,” width=”514″>

Once you are logged in the SQLite shell, it is recommended you first take a look at the Help page of SQLite to get know-how about the SQLite commands.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/7.jpg" data-lazy- height="554" src="data:image/svg xml,” width=”710″>

We will try to run some basic commands to create a database, a table and insert some data into a table in SQLite.

How to Create a Database in SQLite

Since the SQLite database is stored as a file, we can create an SQLite database using the “sqlite3” command.

While logging into the SQLite shell, we need to mention the name of the database we want to use. If there is no database with the provided name, a new database file will be created. If we do not provide any database name, a temporary in-memory database will be created. Note: the temporary in-memory database will be terminated when the SQLite session will be closed.

For example, to create “testdb” database in SQLite, the command would go like this:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/8.jpg" data-lazy- height="76" src="data:image/svg xml,” width=”390″>

After executing the above command, a new database with the name “testdb” will be created in the current working directory. You will be immediately logged into the SQLite session. You can execute the command “.databases” to know which database is connected:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/9.jpg" height="60" src="data:image/svg xml,” width=”274″>

You can see in the screenshot above that the database file is created in the /home/user directory, and the SQLite session is connected to the “testdb”. So, you can also provide the path along with the database name to create and log in to the database session.

After building the database, the next step is to make a table.

How to Make a Table in SQLite

Since SQLite is an SQL-based database management system, the CREATE TABLE command is used for creating a table.

For example, to create a table with the name of “test_student” in the SQLite, the CREATE TABLE command would be like this:

sqlite> CREATE TABLE test_student(


   …> name String,


   …> age Int


   …> );

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/10.jpg" data-lazy- height="93" src="data:image/svg xml,” width=”414″>

A new “test_table” will be created, and you can verify the creation of the table in SQLite by executing the “.tables” command:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/11.jpg" height="58" src="data:image/svg xml,” width=”166″>

You can see and witness in the output that the “test_student” table is listed as a result of the “.tables” command.

Now, let’s see how to put data in an SQLite table.

Inserting Data Into a Table in SQLite

Insertion of data in an SQLite table is as easy as doing it in any other SQL-based database management system. Insert data into the “test_student” table; the INSERT INTO command will be used.

For example, we want to add some new students into the “test_student” table so that the command would go like this:

sqlite> INSERT INTO test_student(name, age)


   …> VALUES (‘John’, 16),


   …> (‘Bob’, 18),


   …> (‘Ivan’, 14);

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/12.jpg" data-lazy- height="94" src="data:image/svg xml,” width=”409″>

How to View a Table Data in SQLite

Now, to view the current state of the table, use the SELECT * FROM table_name command:

sqlite> SELECT * FROM test_student;

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/13.jpg" data-lazy- height="95" src="data:image/svg xml,” width=”339″>

You can see in the output that the three inserted rows are displayed.

Conclusion

In this post, we have learned to install SQLite database management system in the CentOS 8 operating system. Installing the SQLite engine on CentOS 8 is as easy as installing any other package from the DNF package repository on CentOS 8.

Moreover, in this simple starter’s guide, we have learned the primary usage and performed some beginner-level commands like creating a database in SQLite, creating a table, and inserting data into a table in the SQLite database management system.

About the author

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/7011409B3A384F43A8417D1DAC68D179-150×150.jpg60e4c2837f78f.jpg" height="112" src="data:image/svg xml,” width=”112″>

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.