1.第一步:安装sqlite 命令: sudo apt-get install sqlite,安装完成后出现下列信息则表示成功
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
libfolks-telepathy25 ubuntuone-control-panel libpurple0 gir1.2-totem-1.0
gwibber-service telepathy-salut libgtkspell-3-0 python-dirspec
libfolks-eds25 gir1.2-ubuntuoneui-3.0 ubuntuone-couch libindicate-gtk3
python-ubuntuone-control-panel system-config-printer-udev totem-common
libtotem0 php5-gd telepathy-indicator nautilus-sendto-empathy
libmission-control-plugins0 avahi-utils libfolks25 guile-1.8-libs
duplicity
libgwibber-gtk2 folks-common libmcrypt4 libnice10
libgssdp-1.0-3 telepathy-haze libubuntuoneui-3.0-1 gwibber-service-twitter
libavahi-gobject0
libgwibber2 libtelepathy-logger2
libtelepathy-farstream2 python-smbc system-config-printer-common
gnome-games-data telepathy-mission-control-5
telepathy-logger
telepathy-gabble gwibber-service-identica python-gnomekeyring php5-mcrypt
gstreamer0.10-nice python-libproxy
python-egenix-mxdatetime
libgupnp-1.0-4 libpurple-bin python-egenix-mxtools libmeanwhile1 libzephyr4
php5-mysql dbconfig-common
gwibber-service-facebook python-cupshelpers
librsync1 libfarstream-0.1-0 gir1.2-totem-plparser-1.0 libgupnp-igd-1.0-4
empathy-common
使用‘apt-get autoremove‘来卸载它们
将会安装下列额外的软件包:
libsqlite0
建议安装的软件包:
sqlite-doc
下列【新】软件包将被安装:
libsqlite0 sqlite
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 7 个软件包未被升级。
需要下载 201
kB 的软件包。
解压缩后会消耗掉 495 kB 的额外空间。
您希望继续执行吗?[Y/n]y
获取:1
http://cn.archive.ubuntu.com/ubuntu/ precise/universe libsqlite0 i386
2.8.17-7fakesync1build1 [185 kB]
获取:2 http://cn.archive.ubuntu.com/ubuntu/
precise/universe sqlite i386 2.8.17-7fakesync1build1 [16.8 kB]
下载 201 kB,耗时
0秒 (446 kB/s)
Selecting previously unselected package
libsqlite0.
(正在读取数据库 ... 系统当前共安装有 164881 个文件和目录。)
正在解压缩 libsqlite0 (从
.../libsqlite0_2.8.17-7fakesync1build1_i386.deb) ...
Selecting previously
unselected package sqlite.
正在解压缩 sqlite (从
.../sqlite_2.8.17-7fakesync1build1_i386.deb) ...
正在处理用于 man-db
的触发器...
正在设置 libsqlite0 (2.8.17-7fakesync1build1) ...
正在设置 sqlite
(2.8.17-7fakesync1build1) ...
正在处理用于 libc-bin 的触发器...
ldconfig deferred
processing now taking place
felayman@felayman-Inspiron-N4050:~$ sqlite3
2.简单使用安装说明:SQLite version 2.8.17
Enter ".help" for
instructions
sqlite>
我这是2.8.17版本 按照其建议使用命令:.help 出现下列信息
.databases List names and files of
attached databases
.dump ?TABLE? ... Dump the database in
a text format
.echo ON|OFF Turn command
echo on or off
.exit
Exit this program
.explain ON|OFF Turn
output mode suitable for EXPLAIN on or off.
.header(s) ON|OFF
Turn display of headers on or off
.help
Show this message
.indices TABLE
Show names of all indices on TABLE
.mode MODE
Set mode to one of "line(s)",
"column(s)",
"insert", "list", or "html"
.mode insert TABLE
Generate SQL insert statements for TABLE
.nullvalue STRING
Print STRING instead of nothing for NULL data
.output
FILENAME Send output to FILENAME
.output stdout
Send output to the screen
.prompt MAIN CONTINUE
Replace the standard prompts
.quit
Exit this program
.read FILENAME
Execute SQL in FILENAME
.schema ?TABLE?
Show the CREATE statements
.separator STRING Change
separator string for "list" mode
.show
Show the current values for various
settings
.tables ?PATTERN? List names of tables matching
a pattern
.timeout MS Try opening
locked tables for MS milliseconds
.width NUM NUM ... Set column
widths for "column" mode
3.下面主要介绍几个常用的
1.创建数据库,只要我们在登录的时候再sqlite命令后加上一个名词即可如 sqlite mydatabase
则会出现我们自己的数据库文件
seq name file
--- ---------------
----------------------------------------------------------
0
main /home/felayman/mydatabase
1 temp
/var/tmp/sqlite_QCOjy0vJPIoEYhx create
table user(id,name,age);
2.创建一个表 create table user(id,name,age);注意再sqlite中字段是没有类型的。
3.用.scheme命令显示我们刚才创建的数据表,.schema 是用来查看数据库中所有的表的定义内容。如果后面跟了具体的表名称,则显示该表的内容。
sqlite> .schema
create table user(id,name,age);
4.向表中插入数据 我插了三条记录
INSERT INTO user(id,name,age)values(1,‘felay‘,22);
sqlite> INSERT
INTO user(id,name,age)values(2,‘felay1‘,23);
sqlite> INSERT INTO
user(id,name,age)values(3,‘felay2‘,24);
5.查询数据 select * from user;结果如图所示
sqlite> select * from
user;
1|felay|22
2|felay1|23
3|felay2|24
6.更新数据 update user
set age=(age+10); 结果如图
sqlite> select * from
user;
1|felay|32
2|felay1|33
3|felay2|34
7.删除数据delete from user where age=32;,结果如图
1|felay|32
2|felay1|33
3|felay2|34
sqlite> delete from user where
age=32;
sqlite> select * from
user;
2|felay1|33
3|felay2|34
sqlite>
好了上面就是sqlite的最基本的crud操作了。然后说下常用的命令
1..tables-------查看当前数据库中的所有表 如 .tables,因为我的数据库中只有一个user表因此显示如图
sqlite> .tables
user
2..help------帮助我们查看常用的命令技巧,结果如图
sqlite> .help
.databases List
names and files of attached databases
.dump ?TABLE? ...
Dump the database in a text format
.echo ON|OFF
Turn command echo on or off
.exit
Exit this program
.explain ON|OFF
Turn output mode suitable for EXPLAIN on or
off.
.header(s) ON|OFF Turn display of headers on or
off
.help Show
this message
.indices TABLE Show names of all
indices on TABLE
.mode MODE Set
mode to one of "line(s)", "column(s)",
"insert", "list", or
"html"
.mode insert TABLE Generate SQL insert statements for
TABLE
.nullvalue STRING Print STRING instead of nothing
for NULL data
.output FILENAME Send output to
FILENAME
.output stdout Send output to the
screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit
Exit this
program
.read FILENAME Execute SQL in
FILENAME
.schema ?TABLE? Show the CREATE
statements
.separator STRING Change separator string for
"list" mode
.show
Show the current values for various settings
.tables ?PATTERN?
List names of tables matching a pattern
.timeout MS
Try opening locked tables for MS
milliseconds
.width NUM NUM ... Set column widths for "column"
mode
所有常用命令和解释都在help命令中,大家可以看详细文档。