CLS(Command Line Shell)でSQLiteを使う - aktnk/til GitHub Wiki

Ubuntu 22.04LTS ServerにSQLiteの使用手順を記載する

前提条件

  • 使用環境: Ubuntu 22.04 LTS

SQLiteのインストール

  • aptコマンドでsqlite3パッケージをインストールする

    $ sudo apt install sqlite3
    
  • バージョンの確認

    $ sqlite3 --version
    3.45.1 2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257ccalt1 (64-bit)
    

SQLiteのCLS(Command Line Shell)を使う

  • CLSの起動とヘルプの表示

    $ sqlite3 (dbファイル名)
    SQLite version 3.45.1 2024-01-30 16:01:20
    Enter ".help" for usage hints.
    sqlite>.help
    .archive ...             Manage SQL archives
    .auth ON|OFF             Show authorizer callbacks
    <省略>
    .vfslist                 List all available VFSes
    .vfsname ?AUX?           Print the name of the VFS stack
    .width NUM1 NUM2 ...     Set minimum column widths for columnar output
    sqlite>
    
  • dbファイル内のテーブルを表示する

    sqlite> .tables
    table1  table2  table3 …
    sqlite>
    
  • テーブルの内容を表示する(SQL文を実行すればよい)

    sqlite> select * from table1;
    1|2024-08-18 11:37:01.783418  (サンプル表示)
    sqlite>
    
  • CLSを終了する

    sqlite> .quit
    $