Linux Install SQLite Lightweight database

Source: Internet
Author: User
Tags create index memory usage sqlite import database
SQLite, a lightweight database, is a relational database management system that complies with ACID. It is included in a relatively small C library. It is a public domain project established by D. Richard Hipp. Its design goal is embedded, and it has been used in many embedded products at present. It occupies very low resources. In embedded devices, it may only require a few hundred K of memory. It can be used in mainstream operating systems such as Windows / Linux / Unix, and can be combined with many programming languages, such as Tcl, C #, PHP, Java, etc., as well as ODBC interface, which is also comparable to the two open source worlds of Mysql and PostgreSQL In terms of well-known database management systems, its processing speed is faster than them. The first Alpha version of SQLite was born in May 2000. It has been 15 years since 2015, and SQLite has also ushered in a version SQLite 3 has been released.

     Mainstream sqlite3, small memory usage, fast processing speed, cross-platform

01, download

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

02. Installation

bin file installation

    Unzip the downloaded file and put it in / usr / bin /

rpm file installation

  yum install -y sqlite sqlite-devel

03, running

sqlite3

04 、 Test basic commands

sqlite3 test.db #Create a database

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

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

select * from mytable;

### Set formatted query results
sqlite> .mode column;
sqlite> .header on;
sqlite> select * from test;
id value
----------- -------------
1 Micheal
2 Jenny
3 Francis
4 Kerk
.mode column will be set to the column display mode, .header will display the column name

Modify the table structure and add columns:
sqlite> alter table mytable add column email text not null ‘‘ colate nocase ;;
Create a view:
sqlite> create view nameview as select * from mytable;
Create an index:
sqlite> create index test_idx on mytable (value);

Display table structure:
sqlite> .schema [table]
Get all tables and views:
sqlite> .tables
Get the index list of the specified table:
sqlite> .indices [table]
Export database to SQL file:
sqlite> .output [filename]
sqlite> .dump
sqlite> .output stdout
Import database from SQL file:
sqlite> .read [filename]
Format the output data to CSV format:
sqlite> .output [filename.csv]
sqlite> .separator,
sqlite> select * from test;
sqlite> .output stdout
Import data from the CSV file into the table:
sqlite> create table newtable (id integer primary key, value text);
sqlite> .import [filename.csv] newtable
backup database:
/ * usage: sqlite3 [database] .dump> [filename] * /
sqlite3 mytable.db .dump> backup.sql
Restore the database:
/ * usage: sqlite3 [database] <[filename] * /
sqlite3 mytable.db <backup.sql

Help information for 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

    Encounter problems, solve problems, think about problems.

 

Linux install SQLite lightweight database
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.