.db是非关系型数据库SQLite存储文件,可以通过sqlite3查看数据内容

安装sqlite3

yum/apt install sqlite3

查看所有表

.tables

查看表结构

.schema table_name

查看表中所有数据

select * from table_name;

使用Python3脚本

import sqlite3

# 连接到 SQLite 数据库
conn = sqlite3.connect('your_database.db')

# 创建一个游标对象
cursor = conn.cursor()

# 查看所有表
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()

# 显示所有表名
print("Available tables:")
for table in tables:
    print(table[0])

# 提示用户输入要查看的表名
table_name = input("Enter the name of the table you want to view: ")

# 检查输入的表名是否有效
if (table_name,) in tables:
    # 查询该表的数据
    cursor.execute(f"SELECT * FROM {table_name};")
    rows = cursor.fetchall()
  
    # 显示查询结果
    if rows:
        print(f"Data in table '{table_name}':")
        for row in rows:
            print(row)
    else:
        print(f"No data found in table '{table_name}'.")
else:
    print(f"Table '{table_name}' does not exist in the database.")

# 关闭连接
conn.close()
最后修改:2025 年 03 月 07 日
如果觉得我的文章对你有用,请随意赞赏