- serverless database : forget the client-server scheme! Sqlite will only consume CPU and memory when you use it.
- zero configuration : just install the sqlite binaries and use it!
- single database file : the whole database stands in a single file. So it is very easy to handle or move to another computer.
Let's give an introduction about how to use it.
On Debian 5, installation follows the traditionnal method :
apt-get install sqlite3Then, you can start and create a new sqlite database with the sqlite3 command. Just give as an argument the name of the file that will store your database :
luangsay@ramiro:/tmp$ sqlite3 foo.dbYou can use the .help command to see the list of meta-commands. For instance, if we want to list all the tables and know their structure, we would type :
sqlite> CREATE TABLE sa(date int(5), server varchar(20), load5 float(2), iowait int, eth0rx int, eth0tx int, eth1rx int, eth1tx int);
sqlite> .tablesAnd here are some basic insert/select commands :
sa
sqlite> .schema sa
CREATE TABLE sa(date int(5), server varchar(20), load5 float(2), iowait int, eth0rx int, eth0tx int, eth1rx int, eth1tx int);
sqlite> insert into sa values(0955, 'server1', 1.4, 32, 187474, 18747, 0, 0);
sqlite> select * from sa;
955|server1|1.4|32|187474|18747|0|0
Of course, you don't have to use sqlite3 to manage your database. You may use your favorite programming language. Here is an example for python.
First, install the software :
apt-get install python-pysqlite2Then, on the python interpretor, you may type :
>>> import sqlite3
>>> conn = sqlite3.connect( '/tmp/foo.db')
>>> conn.row_factory = sqlite3.Row
>>> cursor = conn.cursor()
>>> cursor.execute('select * from sa')
>>> for line in cursor: print line['date'], line['server'], line['iowait']
...
955 server1 32
>>> conn.commit()
>>> cursor.close()
If you want to discover a bit more about this database, you may refer to the official website.
No comments:
Post a Comment