sqlite3
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在设备的远程 shell 或在主机上,使用 sqlite3
命令行程序来管理由 Android 应用创建的 SQLite 数据库。sqlite3
工具包含许多有用的命令,例如用于输出表格内容的 .dump
,以及用于输出现有表格的 SQL CREATE 语句的 .schema
。您还可以借助该工具随时执行 SQLite 命令。
如需了解完整详情,请参见 SQLite 文档。如需查看其他文档,请访问 sqlite3
以及 SQLite 支持的 SQL 语言规范。
如需通过远程 shell 使用 sqlite3
,请执行以下操作:
- 输入以下命令,以进入远程 shell:
adb [-d|-e|-s {<serialNumber>}] shell
- 在远程 shell 中输入以下命令来启动
sqlite3
工具:
sqlite3
您也可以视需要指定要浏览的数据库的完整路径。模拟器/设备实例会将 SQLite 数据库存储在 /data/data/<package_name>/databases/
目录中。
- 调用
sqlite3
后,您可以在 shell 中发出命令。要退出并返回到 adb 远程 shell,请输入 exit
或按 Control+D。
例如:
$ adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions
.... enter commands, then quit...
# sqlite> .exit
注意:您需要拥有文件系统的根权限才能查看 /data/data
目录层次结构中的文件。
如需在本地(而不是在 shell 中)使用 sqlite3
,请从设备中拉取数据库文件并启动 sqlite3
:
- 将数据库文件从设备复制到主机:
adb pull <database-file-on-device>
- 启动
sqlite3
工具,并指定数据库文件:
sqlite3 <database-file-on-host>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# sqlite3\n\nFrom a remote shell to your device or from your host machine, use the [`sqlite3`](https://www.sqlite.org/) command-line program to manage\nSQLite databases created by Android applications. The `sqlite3` tool includes many\nuseful commands, such as `.dump` to print out the contents of a table and\n`.schema` to print the SQL CREATE statement for an existing table. The tool also gives\nyou the ability to execute SQLite commands on the fly.\n\nRefer to the [SQLite\ndocumentation](https://sqlite.org/docs.html) for full details. For additional documentation, visit\n[`sqlite3`](https://sqlite.org/cli.html) and the\n[SQL language specification](https://sqlite.org/lang.html) supported\nby SQLite.\n\nTo use `sqlite3` from a remote shell:\n\n1. Enter a remote shell by entering the following command: \n\n ```\n adb [-d|-e|-s {\u003cserialNumber\u003e}] shell\n ```\n2. From the remote shell, start the `sqlite3` tool by entering the following command: \n\n ```\n sqlite3\n ```\n\n You can also optionally specify a full path to a database that you want to explore.\n Emulator/device instances store SQLite databases in the directory\n `/data/data/\u003cpackage_name\u003e/databases/`.\n3. Once you invoke `sqlite3`, you can issue commands in the shell. To exit and return to the adb remote shell, enter `exit` or press Control+D.\n\nFor example: \n\n```\n$ adb -s emulator-5554 shell\n# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db\nSQLite version 3.3.12\nEnter \".help\" for instructions\n.... enter commands, then quit...\n# sqlite\u003e .exit\n```\n\n**Note:** You need root access to the file system to view files\nwithin the `/data/data` directory hierarchy.\n\nTo use `sqlite3` locally, instead of within a shell,\npull the database file from the device and start `sqlite3`:\n\n1. Copy a database file from your device to your host machine: \n\n ```\n adb pull \u003cdatabase-file-on-device\u003e\n ```\n2. Start the `sqlite3` tool, specifying the database file: \n\n ```\n sqlite3 \u003cdatabase-file-on-host\u003e\n ```"]]