官网介绍
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.
SQLite是一个C语言库,它实现了一个小型、快速、自包含、高可靠性、全功能的SQL数据库引擎。SQLite是世界上使用最多的数据库引擎。SQLite内置于所有移动电话和大多数计算机中,捆绑在人们每天使用的无数其他应用程序中。
使用压缩包安装
- 下载
wget https://sqlite.org/2020/sqlite-tools-linux-x86-3310100.zip
更多版本见:Sqlite 官网下载页 - 解压至指定文件夹
sudo unzip sqlite-tools-linux-x86-3310100.zip -d /opt
- 查看内容
ll /opt/sqlite-tools-linux-x86-3310100/
wuyujin@ubuntu18:~/Downloads/soft_debian/database$ ll /opt/sqlite-tools-linux-x86-3310100/
total 3960
drwxr-xr-x 2 root root 4096 1月 28 04:27 ./
drwxr-xr-x 11 root root 4096 2月 2 14:03 ../
-rwxr-xr-x 1 root root 560836 1月 28 04:25 sqldiff*
-rwxr-xr-x 1 root root 987012 1月 28 04:27 sqlite3*
-rwxr-xr-x 1 root root 2496032 1月 28 04:26 sqlite3_analyzer*
wuyujin@ubuntu18:~/Downloads/soft_debian/database$
可以看到sqlite是极度精简的。
- 设置环境变量
修改/etc/profile
,添加以下设置:
# SQLite
export SQLITE_HOME=/opt/sqlite-tools-linux-x86-3310100
export PATH=${SQLITE_HOME}/bin:$PATH
重启使最新配置生效。
- 测试环境变量
wuyujin@ubuntu18:~$ sqlite3 --version
3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1
wuyujin@ubuntu18:~$
wuyujin@ubuntu18:~$ sqlite3 --help
Usage: sqlite3 [OPTIONS] FILENAME [SQL]
FILENAME is the name of an SQLite database. A new database is created
if the file does not previously exist.
OPTIONS include:
-ascii set output mode to 'ascii'
-bail stop after hitting an error
-batch force batch I/O
-column set output mode to 'column'
-cmd COMMAND run "COMMAND" before reading stdin
-csv set output mode to 'csv'
-echo print commands before execution
-init FILENAME read/process named file
-[no]header turn headers on or off
-help show this message
-html set output mode to HTML
-interactive force interactive I/O
-line set output mode to 'line'
-list set output mode to 'list'
-lookaside SIZE N use N entries of SZ bytes for lookaside memory
-mmap N default mmap size set to N
-newline SEP set output row separator. Default: '\n'
-nullvalue TEXT set text string for NULL values. Default ''
-pagecache SIZE N use N slots of SZ bytes each for page cache memory
-quote set output mode to 'quote'
-separator SEP set output column separator. Default: '|'
-stats print memory stats before each finalize
-version show SQLite version
-vfs NAME use NAME as the default VFS
wuyujin@ubuntu18:~$
SQLite使用
命令行安装、卸载及安装位置查询
以下要用到的命令:
- 安装软件
apt-get install xxx
或dpkg -i xxx.deb
- 检测软件是否已安装/查看软件安装位置
dpkg -L xxx
或dpkg-query -L xxx
- 卸载软件
apt-get remove xxx
或dpkg -r xxx.deb
shell操作如下:
wuyujin@ubuntu18:~$ # 查询:sqlite3是否安装
wuyujin@ubuntu18:~$ dpkg -L sqlite3
dpkg-query: package 'sqlite3' is not installed
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
wuyujin@ubuntu18:~$
wuyujin@ubuntu18:~$ # 安装sqlite3
wuyujin@ubuntu18:~$ sudo apt-get install sqlite3
[sudo] password for wuyujin:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
sqlite3-doc
The following NEW packages will be installed:
sqlite3
0 upgraded, 1 newly installed, 0 to remove and 21 not upgraded.
Need to get 754 kB of archives.
After this operation, 2,481 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 sqlite3 amd64 3.22.0-1ubuntu0.2 [754 kB]
Fetched 754 kB in 1s (1,321 kB/s)
Selecting previously unselected package sqlite3.
(Reading database ... 177511 files and directories currently installed.)
Preparing to unpack .../sqlite3_3.22.0-1ubuntu0.2_amd64.deb ...
Unpacking sqlite3 (3.22.0-1ubuntu0.2) ...
Setting up sqlite3 (3.22.0-1ubuntu0.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
wuyujin@ubuntu18:~$
wuyujin@ubuntu18:~$ # 查询sqlite3安装位置
wuyujin@ubuntu18:~$ dpkg -L sqlite3
/.
/usr
/usr/bin
/usr/bin/sqldiff
/usr/bin/sqlite3
/usr/share
/usr/share/doc
/usr/share/doc/sqlite3
/usr/share/doc/sqlite3/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/sqlite3.1.gz
/usr/share/doc/sqlite3/changelog.Debian.gz
wuyujin@ubuntu18:~$
wuyujin@ubuntu18:~$ # 卸载sqliet3
wuyujin@ubuntu18:~$ sudo apt-get remove sqlite3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
sqlite3
0 upgraded, 0 newly installed, 1 to remove and 21 not upgraded.
After this operation, 2,481 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 177516 files and directories currently installed.)
Removing sqlite3 (3.22.0-1ubuntu0.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
wuyujin@ubuntu18:~$
wuyujin@ubuntu18:~$ # 再次查询:sqlite3是否安装
wuyujin@ubuntu18:~$ dpkg -L sqlite3
dpkg-query: package 'sqlite3' is not installed
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
wuyujin@ubuntu18:~$
可以看到使用包管理工具直接命令行操作是真的快。
但是如果操作的机器不能联网,那也只能选第一种方案,手动下载压缩包,解压配置运行等。