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命令中,大家可以看詳細文檔。