0x00 背景
做项目需要用到sqlite数据库,这里提供2种方式查询数据。
0x01 命令行读取
yum install sqlite-devel 安装数据库。
访问某个数据库
sqlite3 xxx.db
查看tables
.tables
查询表(这里的sql语法和mysql差不多)
select * from history order by seq desc limit 5;
0x02 python程序读取
import sqlite3
conn = sqlite3.connect('xxx.db')
c = conn.cursor()
c.execute("""select * from history order by seq desc limit 100""")
print(c.fetchall())
c.execute("""select * from config limit 100""")
print(c.fetchall())

本文介绍了在Linux系统中使用sqlite数据库的两种方式:通过命令行工具执行SQL查询以及Python编程连接并读取数据。分别展示了如何通过`sqlite3`命令行和Python的`sqlite3`模块进行数据检索,包括`tables`查看和`orderby`排序等操作。
2052

被折叠的 条评论
为什么被折叠?



