Install SQLite

An important feature of SQLite is zero configuration, which means no complex installation or administration is required. This chapter explains installation Settings on Windows, Linux, and Mac OS X.

Install SQLite on Windows

  • Visit the SQLite Download page to download the pre-compiled binaries from the Windows area.
  • You need to download sqlite-tools-win32-*. Zip and sqlite-dlL-win32 -*. Zip zip files.
  • Create folder C:\ sqLite and unzip the two compressed files in this folder to get sqlite3.def, sqlite3.dll, and sqlite3.exe.
  • Add C:\sqlite to the PATH environment variable, and finally, at the command prompt, use sqlite3 to display the following results.

C:>sqlite3 SQLite version 3.7.15.2 2013-01-09 11:53:05 Enter ". Help "for instructions Enter SQL statements terminated with a ";" sqlite>Copy the code

SQLite creates the database

SQLite’s sqlite3 command is used to create a new SQLite database. You don’t need any special permissions to create a piece of data.

grammar

The basic syntax of the sqlite3 command is as follows:

$ sqlite3 DatabaseName.db
Copy the code

In general, database names should be unique within an RDBMS.

We can also use.open to create a new database file:

So this is verified, we can go inside the db database and create the database by calling.open

sqlite>.open test.db
Copy the code

The above command creates the database file test.db, located in the same directory as the sqlite3 command.

If test.db exists, it will be opened. If it does not, it will be created. Once created, there will be a.db database file in the folder

If you want to create a new database < testdb.db >, the SQLITE3 statement looks like this:

$sqlite3 testdb. db SQLite version 3.7.15.2 2013-01-09 11:53:05 Enter ". Help "for Instructions Enter SQL statements terminated with a ";" sqlite>Copy the code

The command above will create a file testdb.db in the current directory. This file will be used as a database by the SQLite engine. If you have noticed that the sqlite3 command provides an SQLite > prompt after successfully creating the database file.

Once the database is created, you can use SQLite’s.databases command to check if it is in the database list, as shown below:

sqlite>.databases
seq  name             file
--- --------------- ----------------------
0    main             /home/sqlite/testDB.db
Copy the code

You can exit the SQLite prompt using the sqlite. quit command, as shown below:

sqlite>.quit
$
Copy the code

The dump command

You can use the sqlite.dump point command at the command prompt to export the complete database in a text file, as shown below:

$sqlite3 testDB.db .dump > testDB.sql
Copy the code

The command above converts the contents of the entire Testdb.db database into SQLite statements and dumps them to the ASCII text file testdb.sql. You can recover from the generated testdb.sql in a simple way, as follows:

$sqlite3 testDB.db < testDB.sql
Copy the code

The database is empty at this point, and once there are tables and data in the database, you can try the above two programs. Now, let’s move on to the next chapter.