从 Linux shell 与 .db 文件交互

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13052028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 17:36:19  来源:igfitidea点击:

Interacting with a .db file from Linux shell

databaselinuxshellraspberry-pi

提问by scubbo

I recently installed minidlna, a lightweight UPnP server, on my Raspberry Pi. Since this lacks the web interface of other programs such as Mediatomb, I thought it could be an interesting project for me to write one.

我最近在我的 Raspberry Pi 上安装了 minidlna,一个轻量级的 UPnP 服务器。由于这缺少其他程序(例如 Mediatomb)的 Web 界面,因此我认为编写一个对我来说可能是一个有趣的项目。

I believe minidlna stores library information in a single file named "files.db".

我相信 minidlna 将库信息存储在名为“files.db”的单个文件中。



EDIT: I was advised to check the output of file files.db- this was as follows:

编辑:我被建议检查输出file files.db- 这如下:

files.db: SQLite 3.x database, user version 8

files.db: SQLite 3.x database, user version 8



However, I can't find a program that lets me interact with .db files from the shell. I've seen the following programs recommended:

但是,我找不到可以让我与 shell 中的 .db 文件进行交互的程序。我看过以下推荐的程序:

  • isql
  • dbaccess
  • sql
  • SQLite3
  • db.util
  • 数据库
  • 数据库访问
  • sql
  • SQLite3
  • 数据库工具

In the first four cases, sudo apt-get installcannot find the programs.

在前四种情况下,sudo apt-get install找不到程序。

sudo apt-get install db.utilappears to install, but partway through installation, yields the following messages:

sudo apt-get install db.util似乎安装,但在安装过程中,产生以下消息:

Processing triggers for man-db ...
Setting up gcj-4.7-base (4.7.1-1) ...
Setting up libgcj-common (1:4.6.3-7) ...
Setting up libgcj13 (4.7.1-1) ...
Setting up libgcj13-awt (4.7.1-1) ...
Setting up gcj-4.7-jre-headless (4.7.1-1) ...
Illegal instruction
ERROR: gcj-dbtool did fail; known problem on armv6l
Setting up gcj-4.7-jre (4.7.1-1) ...
Setting up gcj-4.7-jre-lib (4.7.1-1) ...
Setting up gcj-jre-headless (4:4.7.1-1) ...
Setting up gcj-jre (4:4.7.1-1) ...
Setting up libservlet2.5-java (6.0.35-5) ...
Setting up libhsqldb-java (1.8.0.10-11) ...
Setting up hsqldb-utils (1.8.0.10-11) ...

Thereafter, which db-util, which db.util, and which dbutildo not yield any results.

此后,which db-utilwhich db.utilwhich dbutil不会产生任何结果。

Is db.util the correct program to be installing to interact with .db files? If so, how can I fix the reported error with gcj-dbtool? If not, could someone recommend a better program?

db.util 是要安装以与 .db 文件交互的正确程序吗?如果是这样,如何使用 gcj-dbtool 修复报告的错误?如果没有,有人可以推荐一个更好的程序吗?

采纳答案by mbarthelemy

You will have to install a package named 'sqlite' or 'sqlite3'.

您必须安装一个名为“sqlite”或“sqlite3”的包。

Then you will be able to interact with your .db file using

然后你将能够使用你的 .db 文件进行交互

$ sqlite3 files.db
> SELECT blah FROM your_table WHERE ......

In your post you mention 'SQLite3', the package name should have no caps letters.

在您的帖子中,您提到了“SQLite3”,包名称不应包含大写字母。

Did you run an apt-cache search sqlite?

你跑了apt-cache search sqlite吗?

回答by mab

You could also use python, since it should already be on your Raspberry Pi and comes with batteries / sqlite3included.

你也可以使用 python,因为它应该已经在你的 Raspberry Pi 上,并且包含电池/ sqlite3

python -c "import sqlite3; print(sqlite3.connect('example.db').cursor().execute('SELECT * FROM stocks ORDER BY price'))"