[note] 2020-11-10 android shell

2020-11-10  本文已影响0人  赶时间的闹钟

android shell 下查看 sqlite 数据库

查看Android板子上的数据库时,常用的办法

  1. 把 db 文件拉出来,然后用 sqlite 工具查看,AS也有对应的常见查看拉出来的文件,mac上,我常用的是 DB Browser for SQLite
  2. 使用调试时,web sqlite,也就是开源库 io.github.skyhacker2:sqliteonweb
  3. 还有就是 root 情况下,使用 shell 中的工具 sqlite3

连接数据库

在 adb shell 里面使用 sqlite3 工具,指令格式为 sqlite3 xxx.db,完成数据库连接

rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite>

常常地,需要访问 /data/data/com.xx.xx/databases/xxx.db 都是需要 root 的

查看数据库信息

连接数据库后,查看帮助指令

sqlite> .help
.backup ?DB? FILE      Backup DB (default "main") to FILE
.bail on|off           Stop after hitting an error.  Default OFF
.binary on|off         Turn binary output on or off.  Default OFF
.clone NEWDB           Clone data into NEWDB from the existing database
.databases             List names and files of attached databases
.dbinfo ?DB?           Show status information about the database
.dump ?TABLE? ...      Dump the database in an SQL text format
                         If TABLE specified, only dump tables matching
                         LIKE pattern TABLE.
.echo on|off           Turn command echo on or off
.eqp on|off            Enable or disable automatic EXPLAIN QUERY PLAN
.exit                  Exit this program
.explain ?on|off?      Turn output mode suitable for EXPLAIN on or off.
                         With no args, it turns EXPLAIN on.
.fullschema            Show schema and the content of sqlite_stat tables
.headers on|off        Turn display of headers on or off
.help                  Show this message
.import FILE TABLE     Import data from FILE into TABLE
.indexes ?TABLE?       Show names of all indexes
                         If TABLE specified, only show indexes for tables
                         matching LIKE pattern TABLE.
.limit ?LIMIT? ?VAL?   Display or change the value of an SQLITE_LIMIT
.log FILE|off          Turn logging on or off.  FILE can be stderr/stdout
.mode MODE ?TABLE?     Set output mode where MODE is one of:
                         ascii    Columns/rows delimited by 0x1F and 0x1E
                         csv      Comma-separated values
                         column   Left-aligned columns.  (See .width)
                         html     HTML <table> code
                         insert   SQL insert statements for TABLE
                         line     One value per line
                         list     Values delimited by .separator strings
                         tabs     Tab-separated values
                         tcl      TCL list elements
.nullvalue STRING      Use STRING in place of NULL values
.once FILENAME         Output for the next SQL command only to FILENAME
.open ?FILENAME?       Close existing database and reopen FILENAME
.output ?FILENAME?     Send output to FILENAME or stdout
.print STRING...       Print literal STRING
.prompt MAIN CONTINUE  Replace the standard prompts
.quit                  Exit this program
.read FILENAME         Execute SQL in FILENAME
.restore ?DB? FILE     Restore content of DB (default "main") from FILE
.save FILE             Write in-memory database into FILE
.scanstats on|off      Turn sqlite3_stmt_scanstatus() metrics on or off
.schema ?TABLE?        Show the CREATE statements
                         If TABLE specified, only show tables matching
                         LIKE pattern TABLE.
.separator COL ?ROW?   Change the column separator and optionally the row
                         separator for both the output mode and .import
.shell CMD ARGS...     Run CMD ARGS... in a system shell
.show                  Show the current values for various settings
.stats on|off          Turn stats on or off
.system CMD ARGS...    Run CMD ARGS... in a system shell
.tables ?TABLE?        List names of tables
                         If TABLE specified, only list tables matching
                         LIKE pattern TABLE.
.timeout MS            Try opening locked tables for MS milliseconds
.timer on|off          Turn SQL timer on or off
.trace FILE|off        Output each SQL statement as it is run
.vfsname ?AUX?         Print the name of the VFS stack
.width NUM1 NUM2 ...   Set column widths for "column" mode
                         Negative values right-justify

可以使用对应的指令,但常用的一般有

查看已连接数据库

sqlite>.database 
seq  name             file
---  ---------------  ----------------------------------------------------------
0    main             /data/data/com.xx.xx/databases/UserDatabase.

表操作

查看当前(或者制定name的数据库)的所有表

sqlite>.tables
User               android_metadata   room_master_table

指定输出列表内容的格式,column 讲以列的方式展示

sqlite> .mode column
sqlite>

使用 sqlite 数据库语句

sqlite> .mode line
select * from User;
   name = KK11161
feature = i3UAgAAAAAAMBAAAAABJQwAAsUMAANdDAADJQwCAr0MAAOBAAICCQwAAyUMAAPhDAAC6QwAAtEIAAAAAAAD4QwAA10MAAIJDAICOQwCAh0MAAOdDAAAxQwAAn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gJpDAAD0QwAAkEEAAL5CAAAsQgCAiEMAAIJDAACEQgAA4EAAANJCAAC+QgAALEIAAHhCAAARQwAA9EMAANdDAICPQwCA70MAACVDAICPQwCAmkMAAKdDAACwQQAAyUMAAIJDAACEQgCAmkMAALFDAABBQwCAvkMAANdDAABBQw==
quality = 9.99787902832031

   name = C00020
feature =
quality = 9.97407150268555

   name = C00021
feature =
quality = 9.97407150268555
sqlite>

退出 sqlite3

退出 sqlite3 的三种方式,.quit, .exit, 3次 ctrl + c

rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> .quit
rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> .exit
rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
1|rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> ^[[C^[[C
   ...> ^C^C^C1|rk3399_JH:/sdcard #
1|rk3399_JH:/sdcard #
上一篇 下一篇

猜你喜欢

热点阅读