安装sqlite3数据库:
1、从https://www.sqlite.org/download.html下载安装包,编译安装
sqlite-autoconf-3330000.tar.gz
2、#tar -zxvf sqlite-autoconf-3330000.tar.gz
3、#cd sqlite-autoconf-3330000
4、#./configure --prefix=/opt/sqlite3
5、#make && make install
因为python中没有sqlite3的,需要对python程序进行重新的编译安装。
1、python 查看程序的版本
2、https://www.python.org/ 下载对应版本的介质
3、tar -zxvf Python-2.6.6.tgz
4、修改setup.py,在sqlite_inc_paths中增加一行,其内容是上一步sqlite3编译安装的路径
1097 # We hunt for #define SQLITE_VERSION "n.n.n" 1098 # We need to find >= sqlite version 3.0.8 1099 sqlite_incdir = sqlite_libdir = None 1100 sqlite_inc_paths = [ '/usr/include', 1101 '/usr/include/sqlite', 1102 '/usr/include/sqlite3', 1103 '/usr/local/include', 1104 '/usr/local/include/sqlite', 1105 '/usr/local/include/sqlite3', 1106 '/opt/sqlite3', #新增此行 1107 ] 保存退出。
5、# ./configure
6、# make && make install
7、验证结果
python
>> import sqlite3 没有报错
python操作sqlite3:
import sqlite3
conn = sqlite3.connect('wucai.db')
cur = conn.cursor()
#cur.execute('create table t1(col1 int,col2 varchar(10),col3 varchar(3))')
#cur.executemany('INSERT INTO t1 VALUES (?,?,?)',[(1,'name1','name1'),(2,'name2','name2')]) 批量插入
cur.execute('select col1,col2,col3 from t1')
#cur.execute('delete from t1')
result = cur.fetchall()
for line in result:
print(line[2]) 可以获取某些行,某些字段的值
conn.commit()
conn.close()