sqlite3
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trên màn hình shell từ xa đến thiết bị của bạn hoặc trên máy chủ lưu trữ, hãy sử dụng chương trình dòng lệnh sqlite3
để quản lý cơ sở dữ liệu SQLite do ứng dụng Android tạo ra. Công cụ sqlite3
có nhiều lệnh hữu ích chẳng hạn như .dump
để in nội dung của bảng và .schema
để in câu lệnh SQL CREATE cho bảng hiện có. Công cụ này cũng cho phép bạn thực thi các lệnh SQLite trong quá trình triển khai.
Tham khảo tài liệu về SQLite để biết đầy đủ thông tin chi tiết. Để xem thêm tài liệu, hãy truy cập vào sqlite3
và bài viết đặc tả ngôn ngữ SQL mà SQLite hỗ trợ.
Cách sử dụng sqlite3
trên màn hình shell từ xa:
- Nhập một màn hình shell từ xa bằng cách nhập lệnh sau:
adb [-d|-e|-s {<serialNumber>}] shell
- Trên màn hình shell từ xa, hãy khởi động công cụ
sqlite3
bằng cách nhập lệnh sau đây:
sqlite3
Bạn cũng có thể tuỳ ý chỉ định một đường dẫn đầy đủ đến cơ sở dữ liệu mà bạn muốn khám phá.
Các thực thể của trình mô phỏng/thiết bị lưu trữ cơ sở dữ liệu SQLite trong thư mục /data/data/<package_name>/databases/
.
- Sau khi gọi
sqlite3
, bạn có thể đưa ra các lệnh trong shell. Để thoát và quay lại màn hình shell từ xa của adb, hãy nhập exit
hoặc nhấn tổ hợp phím Control + D.
Ví 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
Lưu ý: Bạn cần có quyền truy cập gốc vào hệ thống tệp để xem tệp trong hệ phân cấp của thư mục /data/data
.
Để sử dụng sqlite3
cục bộ, thay vì trong một shell, hãy lấy tệp cơ sở dữ liệu trên thiết bị và khởi động sqlite3
:
- Sao chép tệp cơ sở dữ liệu từ thiết bị của bạn vào máy chủ:
adb pull <database-file-on-device>
- Khởi động công cụ
sqlite3
, chỉ định tệp cơ sở dữ liệu:
sqlite3 <database-file-on-host>
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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 ```"]]