Linux安裝SQLite輕量級資料庫

來源:互聯網
上載者:User

標籤:and   load   header   佔用   abs   解決問題   lock   匯出資料   open   

  SQLite,是一款輕型的資料庫,是遵守ACID的關係型資料庫管理系統,它包含在一個相對小的C庫中。它是D.RichardHipp建立的公有領域項目。它的設計目標是嵌入式的,而且目前已經在很多嵌入式產品中使用了它,它佔用資源非常的低,在嵌入式裝置中,可能只需要幾百K的記憶體就夠了。它能夠Windows/Linux/Unix等等主流的作業系統,同時能夠跟很多程式語言相結合,比如 Tcl、C#、PHP、Java等,還有ODBC介面,同樣比起Mysql、PostgreSQL這兩款開源的世界著名資料庫管理系統來講,它的處理速度比他們都快。SQLite第一個Alpha版本誕生於2000年5月。 至2015年已經有15個年頭,SQLite也迎來了一個版本 SQLite 3已經發布。

     主流的sqlite3,佔用記憶體小,處理時速度快,跨平台

01、下載

https://www.sqlite.org/download.html

02、安裝

bin檔案安裝

    解壓下載的檔案,放到 /usr/bin/

rpm檔案安裝

  yum install -y sqlite   sqlite-devel

03、運行

sqlite3

04、測試基本命令

sqlite3   test.db     #建立資料庫

create table mytable(id integer primary key, value text);

insert into mytable(id, value) values(1, ‘Micheal‘);

select * from mytable;

###設定格式化查詢結果
sqlite> .mode column;
sqlite> .header on;
sqlite> select * from test;
id     value
----------- -------------
1      Micheal
2      Jenny
3      Francis
4      Kerk
.mode column 將設定為列顯示模式,.header 將顯示列名

修改表結構,增加列:
sqlite> alter table mytable add column email text not null ‘‘ collate nocase;;
建立視圖:
sqlite> create view nameview as select * from mytable;
建立索引:
sqlite> create index test_idx on mytable(value);

顯示表結構:
sqlite> .schema [table]
擷取所有表和視圖:
sqlite > .tables
擷取指定表的索引列表:
sqlite > .indices [table ]
匯出資料庫到 SQL 檔案:
sqlite > .output [filename ]
sqlite > .dump
sqlite > .output stdout
從 SQL 檔案匯入資料庫:
sqlite > .read [filename ]
格式化輸出資料到 CSV 格式:
sqlite >.output [filename.csv ]
sqlite >.separator ,
sqlite > select * from test;
sqlite >.output stdout
從 CSV 檔案匯入資料到表中:
sqlite >create table newtable ( id integer primary key, value text );
sqlite >.import [filename.csv ] newtable
備份資料庫:
/* usage: sqlite3 [database] .dump > [filename] */
sqlite3 mytable.db .dump > backup.sql
恢複資料庫:
/* usage: sqlite3 [database ] < [filename ] */
sqlite3 mytable.db < backup.sql

sqlite3的協助資訊

sqlite> .help
.backup ?db? file      backup db (default "main") to file
.bail on|off           stop after hitting an error.  default off
.databases             list names and files of attached databases
.dump ?table? ...      dump the database in an sql text format
                         if table specified, only dump tables matching
                         like pattern table.
.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.
.genfkey ?options?     options are:
                         --no-drop: do not drop old fkey triggers.
                         --ignore-errors: ignore tables with fkey errors
                         --exec: execute generated sql immediately
                       see file tool/genfkey.readme in the source
                       distribution for further information.
.header(s) on|off      turn display of headers on or off
.help                  show this message
.import file table     import data from file into table
.indices ?table?       show names of all indices
                         if table specified, only show indices for tables
                         matching like pattern table.
.load file ?entry?     load an extension library
.mode mode ?table?     set output mode where mode is one of:
                         csv      comma-separated values
                         column   left-aligned columns.  (see .width)
                         html     html <table> code
                         insert   sql insert statements for table
                         line     one value per line
                         list     values delimited by .separator string
                         tabs     tab-separated values
                         tcl      tcl list elements
.nullvalue string      print string in place of null values
.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
.restore ?db? file     restore content of db (default "main") from file
.schema ?table?        show the create statements
                         if table specified, only show tables matching
                         like pattern table.
.separator string      change separator used by output mode and .import
.show                  show the current values for various settings
.tables ?table?        list names of tables
                         if table specified, only list tables matching
                         like pattern table.
.timeout ms            try opening locked tables for ms milliseconds
.width num num ...     set column widths for "column" mode
.timer on|off          turn the cpu timer measurement on or off

    遇到問題,解決問題,思考問題。

 

Linux安裝SQLite輕量級資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.