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

遇到问题,解决问题,思考问题。

最新文章

  1. 【转】sublime配置默认浏览器+多浏览器快捷键
  2. 深入理解DOM事件类型系列第三篇——变动事件
  3. javascript数据结构-介绍
  4. Arraylist&lt;E&gt;
  5. Android中dip、dp、sp、pt和px的区别
  6. 动态布局--动态修改RelativeLayout宽高的方法
  7. avalon2学习教程15指令总结
  8. 1.素数判定(如何输出\n,\t,不用关键字冲突)
  9. NAND驱动
  10. cocos 自适应屏幕分辨率
  11. Android事件分发原理
  12. loadrunner java 缺少必要的导入包报错
  13. vue-router2.0简单路由嵌套
  14. Github 快速建库上传本地代码
  15. 微信网页授权 通过code获取openid 报错40163 code been used
  16. JSP 标准标签库JSTL
  17. cf932E. Team Work(第二类斯特灵数 组合数)
  18. CAS适用场景
  19. String 字符串相加比较
  20. Windows 系统采用批处理命令修改 ip 地址

热门文章

  1. NativeXml
  2. [翻译] 用 ObjectiveSugar 扩展NSArray NSDictionary NSSet NSNumber
  3. java 数据流的处理
  4. coursera课程Text Retrieval and Search Engines之Week 1 Overview
  5. IIS HTTP 错误 404.17 - Not Found 解决方法
  6. 稀疏数据压缩查询方法:Rank &amp; Select 操作
  7. zoj 2860 四边形优化dp
  8. MD5 SHA1 哈希 签名 碰撞 MD
  9. SQL基础(一):SQL语法和命令
  10. Sql Server-查询一列的数据进行拼接