阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux安装SQLite轻量级数据库

132次阅读
没有评论

共计 4270 个字符,预计需要花费 11 分钟才能阅读完成。

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

如何在 Ubuntu 15.04 上安装带 JSON 支持的 SQLite 3.9.1  http://www.linuxidc.com/Linux/2016-02/128209.htm

SQLite3 简单操作 http://www.linuxidc.com/Linux/2016-01/127969.htm

SQLite3 中存储类型和数据类型结合文档解析  http://www.linuxidc.com/Linux/2015-08/121971.htm

SQLite3 安装、基本操作 http://www.linuxidc.com/Linux/2012-05/60452.htm

Ubuntu 12.04 下 SQLite 数据库简单应用 http://www.linuxidc.com/Linux/2012-06/63379.htm

Ubuntu 12.04 下安装 SQLite 及其使用方法 http://www.linuxidc.com/Linux/2013-08/89155.htm

SQLite 数据库入门基础教程 http://www.linuxidc.com/Linux/2014-06/103587.htm

SQLite 的详细介绍:请点这里
SQLite 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141342.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计4270字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中