How to install or get access to sqlite3 from adb shell

42,431

Solution 1

I use Rajath's technique... Adb "Pull" the db from the emulator/device, work on it, then adb "push" it back onto/into the emulator device.

also: I use the free SQLite Editor from the Android Market. I have not rooted my LG Ally and therefor can only edit database tables on my sdcard with SQLite Editor.

Rajath suggests using the adb to push and pull the databases to and from the emulator/device. The work on the database with the windows (or whatever) sqlite3 program you have. He does not suggest pusing the windows sqlite3 onto the Android device, IMHO.

I note that java/android "query()" sends actual SQL commands programmacitacly to ones program with user input. I conclude that sqlite3 is in Android somewhere.

When using the emulator Dev Tools is available, and way down at the bottom of the list is the Terminal Emulator. This allows exploration of file structure of Android in the emulator. However using "adb shell" from the PC has root permissions.

good luck. cactus mitch

Solution 2

Download this app from google play will help you install sqlite3 on android https://play.google.com/store/apps/details?id=ptSoft.util.sqlite3forroot

Solution 3

You don't need root to pull the database from your device. Simply run the following commands:

adb shell run-as <package-name> "cp databases/<db_name>.db /sdcard/ && exit"
adb pull /sdcard/<db_name>.db ~/Downloads/

From there, you can use sqlite3 for whatever operating system you're using (http://www.sqlite.org/download.html), or a sqlite browser such as "DB Browser for SQLite" (http://sqlitebrowser.org/)

Share:
42,431
DNRN
Author by

DNRN

C# developer at Cordura A/S in Århus Denmark. Developing Django pages and playing around with XNA in the spare time :D

Updated on April 08, 2020

Comments

  • DNRN
    DNRN about 4 years

    I need a way to install or somehow get access to sqlite3 in the adb shell. I have rooted my device.

    I've tried to find an answer but the closed I could come is: Why do I get a "sqlite3: not found" error on a rooted Nexus One when I try to open a database using the adb shell?

    But I don't think it's good idea to push my windows sqlite3.exe on a linux system?

    So is it possible to install the sqlite3 terminal browser somehow?

    [SOLUTION]

    From the different comments and some asking around at #android-dev (irc), I found a solution. First I copied the database file to my desktop. But fist I had to install BusyBox, because cp isn't included?!? After that ran I into the problem that I couldn't pull or push from anywhere but /sdcard/ . I could then use /sdcard/ as a "middle station" and pull/push my db.

    Then I got exhausted! I really had to have my sqlite terminal explore. Then I got the idea to start the emulator pull the sqlite binary from /system/xbin/sqlite3. Then remount /system with rw:

    # mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
    

    and push sqlite to the /sdcard/, and from there copy it to /system/xbin/

    Now it works :D

  • Harry Mad
    Harry Mad over 9 years
    I am getting Permission denied, when i am executing ls command to find database. what can be the problem ?
  • Nick
    Nick over 9 years
    You have to be on an emulator or rooted.
  • pevik
    pevik over 8 years
    It would be nice to be able to run it from host. Eg: adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings‌​.db 'select * from "secure";'. In my case it gets stack, I have to log into adb shell and run it from there.