Linux under Berkeley-db and Python binding installation

Source: Internet
Author: User

1. Download source code Shell > wget http://download.oracle.com/berkeley-db/db-5.3.21.tar.gzshell > Wget http://pypi.python.org /packages/source/b/bsddb3/bsddb3-5.3.0.tar.gz#md5=d5aa4f293c4ea755e84383537f74be822, unzip, go to directory 3, install Berkeley-db Shell > CD Build_unix/shell >. /dist/configure # Default installation in/usr/local/berkeleydb.5.3 Shell > Makeshell > Sudo make install4, install Python Bindingshell ; sudo python setup.py--lflags= "/usr/local/berkeleydb.5.3/lib/libdb-5.3.so" Install
The BSDDB module is the module used to operate the BDB, BDB is the famous Berkeley DB, and its performance is very good, and the MySQL storage back-end engine supports BDB way. Here is a brief introduction to some of the ways to use BSDDB.

BDB is different from the general relational database, it can only store data is a pair of key and value of data, use like a python dictionary, it can not directly represent multiple fields, when you want to store multiple fields of data, only the data as a whole can be stored in value.
the first question to use with BSDDB is what data access method to use, BDB supports four kinds: btree, hash, queue, recno. Here's what the difference is, btree is the tree structure to store the data, the query is fast, can store arbitrary complex key and value. Hash is the hash algorithm used, the speed is actually similar to Btree, but when the amount of data is particularly large, you should use hash. A queue is a queued operation that has a limit that can only store fixed-length data, which means that value is fixed! But the queue can keep the data in first-out, and the data is inserted in a special optimization, and provide row-level locks. The key of the queue must be a number. Recno is similar to a queue, but it can support variable-length value, and its key is also a number.
#-*-encoding:gb2312-*-import os, sys, stringimport bsddb, timehome = "db_home" filename = "test.db" Try:    # Create home directory 
   os.mkdir (Home) except:    pass# Create a database environment dbenv = BSDDB.DB.DBENV () # Open the database environment Dbenv.open (Home, Bsddb.db.DB_CREATE | Bsddb.db.DB_INIT_MPOOL) # Create a database object d = Bsddb.db.DB (dbenv) # Open the database, the second parameter here is specifying what data access method to use # BTREE is Bsddb.db.DB_BTREE, HASH is bsddb.db.db_hash# Queu is Bsddb.db.DB_QUEUE,  recno is bsddb.db.DB_RECNOd.open (filename, Bsddb.db.DB_BTREE, Bsddb.db.DB_CREATE, 0666) # Insert a piece of data, note that the queue and RECNO key cannot be a string, it should be the number d.put (' test1 ', ' Zhaowei ')    print d.items () # Close, The data is then written back to the file D.close () Dbenv.close ()




https://www.jcea.es/programacion/pybsddb_doc/about Python berkeley-db document address under related Linux!

Linux under Berkeley-db and Python binding installation

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.