本記事では、ラズベリーパイのRaspbian busterにSQLite3をインストールし、 データベースファイル作成、テーブル作成およびSQLを実行までの記事になります。
$ lsb_release -dr Description: Raspbian GNU/Linux 10 (buster)
LXTerminal を使ってaptコマンドでSQLite3をインストール手順になります。
sudo apt update sudo apt -y upgrade
sudo apt install sqlite3 -yちなみにインストールするSQLite3パッケージの情報は以下の通りです。
$ apt show sqlite3 Package: sqlite3 Version: 3.27.2-3 Priority: optional Section: database Maintainer: Laszlo Boszormenyi (GCS) <gcs@debian.org> Installed-Size: 2,278 kB Depends: libc6 (>= 2.28), libreadline7 (>= 6.0), zlib1g (>= 1:1.2.0), libsqlite3-0 (= 3.27.2-3) Suggests: sqlite3-doc Homepage: https://www.sqlite.org/ Download-Size: 839 kB APT-Sources: http://ftp.jaist.ac.jp/raspbian buster/main armhf Packages Description: Command line interface for SQLite 3 SQLite is a C library that implements an SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process.
注意
今回インストールしたSQLiteはバージョン3になります。(SQLite3)
SQLiteのバージョン2のパッケージ名はsqliteになります。
SQLite3は起動時にデータベースファイルを引数に渡すと、それがデータベースファイルになります。
データベースファイルを作成してみます。
sqlite3 db.sqlite3実行時の出力になります。
$ sqlite3 db.sqlite3 SQLite version 3.27.2 2019-02-25 16:06:06 Enter ".help" for usage hints. sqlite>
sqlite> .quit
$ ls *.sqlite3 db.sqlite3以上のように、sqlite3コマンドにデータベースファイルを指定し、無ければ作成され
以下の手順で上記で作成したデータベースファイルにテーブルを作成してみます。
sqlite3 db.sqlite3
$ sqlite3 db.sqlite3 SQLite version 3.27.2 2019-02-25 16:06:06 Enter ".help" for usage hints. sqlite>
sqlite> create table t ( id integer primary key, type text);
sqlite> .schema t CREATE TABLE t ( id integer primary key, type text);
上記でデータベースファイルおよびテーブルの作成を行いました。
以下では作成したテーブルにデータをINSERTしSELECTしてみます。
sqlite> select * from t; 1|Raspbian 2|UbuntuMate 3|CentOS
以上、ラズベリーパイにSQLite3をインストールし動作確認までの記事でした。