读取sqlite数据库的2种方式

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程序读取

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())
相关推荐
xywww1684 小时前
大模型 API 选型实战:GPT、Gemini、Claude 接入时该看哪些指标?
运维·服务器·人工智能·python·gpt·langchain
欢呼的太阳8 小时前
数据库设计Step by Step (10)——范式化
服务器·数据库·oracle
夜雪一千8 小时前
Python enumerate() 函数完整详解:遍历同时获取索引,告别手动计数
服务器·windows·python
喜欢的名字被抢了9 小时前
MySQL基础入门:从零理解数据库与SQL
数据库·mysql·教程
能有时光9 小时前
PyTorch KernelAgent 源码解读 ---(4)--- ExtractorAgent
人工智能·pytorch·python
_Jimmy_9 小时前
Python 协程库如何使用以及有哪些使用场景
python
aqi0010 小时前
15天学会AI应用开发(十七)使用LangGraph实现会话记忆功能
人工智能·python·大模型·ai编程·ai应用
Elastic 中国社区官方博客10 小时前
如何比较两个 Elasticsearch 索引并找出缺失的文档
大数据·运维·数据库·elasticsearch·搜索引擎
西门吹-禅10 小时前
java springboot N+1问题
java·开发语言·spring boot
第一程序员10 小时前
Rust Agent 子进程执行:Command 之前,先定义输入和超时
python·rust·github