46
# sqlite3 /data/data/com.moodme.android/databases/moodme
sqlite3 /data/data/com.moodme.android/databases/moodme
sqlite3: not found
Julian A.
  • 10,928
  • 16
  • 67
  • 107

6 Answers6

93

As an alternative (may not be secure or even good idea though) you can always upload the sqlite3 binary to /system/bin this worked for me:

First lets mount /system/ to allow read/write (rw)

$ adb shell
$ su
# mount -o remount,rw /system

in another terminal change directory (cd) to where sqlite3 is and lets push it

$ ls
sqlite3
$ adb push sqlite3 /sdcard/

Now back to the other shell lets copy and change permissions of the binary

# cat /sdcard/sqlite3 > /system/bin/sqlite3
# chmod 4755 /system/bin/sqlite3

Now lets mount back /system/ as read only (ro)

# mount -o remount,ro /system

And now we can use sqlite3 from shell:

# sqlite3 /data/data/com.telly/databases/fun.db
SQLite version 3.7.4
Enter ".help" for instructions
sqlite> .tables
android_metadata  lulz               

Note: I'm using the sqlite3 binary that comes with "SuperOneClickv1.6.5-ShortFuse"

You can always pull sqlite3 binary from emulator:

Start an emulator and then from a terminal

$ adb pull /system/xbin/sqlite3

If you are lazy like me you can download one right here for ICS or before or for Jelly Bean and later here

Make sure to use the proper one for your Android version as you may get eloc_library[1306]: 14446 cannot locate 'sqlite3_enable_load_extension'... or similar errors on execute

Michael Kohne
  • 11,888
  • 3
  • 47
  • 79
eveliotc
  • 12,863
  • 4
  • 38
  • 34
  • Can you please tell me where I can find sqlite3 for NexusOne on Gingerbread? Thank you. – michael Mar 09 '11 at 18:02
  • Would be grat if we could do that inside an application to fix the issue for our users! – Waza_Be Sep 27 '11 at 17:41
  • where do you find that sqlite3 command build for your device? or you build it by yourself? – hugemeow Nov 19 '12 at 13:19
  • To get sqlite3 to bin directory, I pushed it to the sdcard like adb push sqlite3 /sdcard. Then I abd shell; su; cp /sdcard/sqlite3 /system/bin/sqlite3. That worked for me. – user123321 Oct 23 '13 at 00:23
  • 1
    and this is a link to SQLite SQLite version 3.8.6 2014-08-15 http://s000.tinyupload.com/index.php?file_id=52096553461674354126 in case you get "SQLite header and source version mismatch" error for recent OS (I got this error for Android L) – Kazuki Dec 21 '14 at 01:48
  • To me, besides, I have to copy `/system/lib/libsqlite.so` and `/system/lib/libsqlite_jni.so` from the emulator to my device. (Of course `/system/lib/` folder on the device) Then it works, finally. – Weekend Apr 26 '16 at 08:41
21

On the Android emulator, sqlite3 is in /system/xbin. There is no /system/xbin on a Nexus One (Android 2.2). Hence, I suspect that sqlite3 is not installed on the Nexus One.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    If you install cyanogenmod it has sqlite3 working in the shell. – Nathan Schwermann Sep 05 '10 at 17:31
  • But doesn't device need it to create and read sqlite3 databases? Also, if it's not on the Nexus One, is there a way to get it on there? – Julian A. Sep 05 '10 at 17:32
  • 3
    @Julian: "But doesn't device need it to create and read sqlite3 databases?" -- Why would it? SQLite is a library, attached to an Android app via JNI. `sqlite3` is a command-line executable. "Also, if it's not on the Nexus One, is there a way to get it on there?" -- you're welcome to try to find an ARM port and see if you can get it working. I'm dubious that it's really the solution for whatever problem you think you have, though. Android apps don't need it. For development, you can pull the database off your rooted phone and examine it on your development machine. – CommonsWare Sep 05 '10 at 17:44
  • Ah. Ok. Thanks for explaining. There wasn't really a problem as such. I was just exploring whether it was necessary to always have to "pull' the database to examine it. – Julian A. Sep 05 '10 at 18:54
  • 3
    @Julian: On the emulator, no. On a device, yes, rooted or not. Also, if you're an Eclipse user, you might want to peek at MOTODEV Studio for Android. I seem to recall they had an integrated SQLite editor for on-emulator databases, and that might work with your rooted phone. Behind the scenes, it probably just does a pull, but it might be more convenient. – CommonsWare Sep 05 '10 at 19:02
  • 1
    @IgorGanapolsky: There is no guarantee that a command-line `sqlite3` client binary will exist on any device. – CommonsWare May 22 '18 at 14:44
12

From the answer of evelio, I had problem to push the sqlite3 file to /system/bin. So, instead, I have pushed it to the /sdcard.

In this thread I found the right Solution (answer of Kila): How can I install sqlite3 on rooted NexusOne runs Gingerbread

$ adb push sqlite3 /sdcard/
$ adb shell
$ su
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
# dd if=/sdcard/sqlite3 of=/system/bin/sqlite3
# chmod 4755 /system/bin/sqlite3
# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system 

It works on my Samsung Galaxy S II with 2.3.3.

Community
  • 1
  • 1
jiahao
  • 3,373
  • 2
  • 35
  • 36
  • 1
    Works on rooted Nexus-S running Android ICS 4.0.4 using the sqlite3 binary from SuperOneClick (http://shortfuse.org/?page_id=2 / http://download.cnet.com/SuperOneClick/3000-2094_4-75447027.html) – Chris Blunt May 14 '12 at 12:51
  • Works on GT-i9100 4.03 ICS by pulling sqlite3 from emulator and then pushing up as instructed. – Eugene van der Merwe Aug 27 '12 at 20:54
  • It worked on my galaxy s II with ICS but with the update to 4.1 JB, I have the following error cannot locate 'sqlite3_enable_load_extension'... CANNOT LINK EXECUTABLE – mrroboaat May 28 '13 at 12:13
5

To install sqlite3 on NON-ROOTED devices, here is a way that has been proved working on my Galaxy S3, FYR.

$ adb -e pull /system/xbin/sqlite3  # get sqlite3 binary from emulator with the same CPU arch.
$ adb -d push sqlite3 /mnt/sdcard   # push it
$ adb -d shell
$ run-as <PACKAGE_NAME>             # run as your app, which should be debuggable.
$ cd databases; pwd
/data/data/<PACKAGE_NAME>/databases
$ cat /mnt/sdcard/sqlite3 > sqlite3 # copy it to internal storage directory
$ ls -l sqlite3
-rw-rw-rw- u0_a138  u0_a138     36860 2014-03-26 06:37 sqlite3
$ chmod 777 sqlite3                 # change mode bits, to be executable

$ ./sqlite3                         # now it works on your NON-ROOTED device
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
Jeremy Kao
  • 853
  • 10
  • 14
  • I got permission denied – Fermat's Little Student Apr 30 '14 at 05:05
  • 3
    Also trying to get this working on a non-rooted 4.4 device. Your steps almost work except that after using run-as the app user account doesn't have permission to /mnt/sdcard anymore (used to work in older Android versions; must be a recent change). I worked around that part by putting the sqlite3 binary in the app assets folder and then extracting it to the databases folder on the first app run. – dfinn Apr 28 '15 at 22:34
  • I got when using ./sqlite3 sh: ./sqlite3: not executable: magic 7F45 – Amit Thaper Jul 07 '15 at 06:21
  • @AndroidDeveloper Sounds like the sqlite3 you put on there is for a different architecture. Make sure to pull it from an emulator with the same architecture as your target device, as Jeremy wrote in first line comment. – Andrew Smart Feb 01 '16 at 03:04
  • 1
    @AndroidDeveloper You may've accidentally pushed the sqlite3 included in platform-tools (same folder as adb is in) which is either x86 or x86_64. – Andrew Smart Feb 01 '16 at 03:16
2

On the Nexus 4 do the following :

adb shell
$ su
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
# dd if=/sdcard/sqlite3 of=/system/xbin/sqlite3
# chmod 777 /system/xbin/sqlite3
# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system

Notice the folder is /system/xbin and the chmod is 777

vinzzz
  • 2,084
  • 2
  • 14
  • 23
0

Some more information that may help someone about this issue

For the people who wonder where to get a working sqilte3 file binary to copy:

You can use the emulator to get a working binary. You must before check if your build is based on _86, _64, or ARM and replicate this image or you may get an incompatible version that will cause an err.

Checking which version is your android device

https://www.quora.com/How-can-I-check-whether-my-Android-phone-is-32-bit-or-64-bit

Building ARM in android studio

Android Studio - How Can I Make an AVD With ARM Instead of HAXM?


Then, use the notes below to move files between your machine and back to the android device.

Making adb writable

Android Emulator sdcard push error: Read-only file system

Copying files from adb to local device machine

How to copy selected files from Android with adb pull

On a rooted device nexus 4 these links with the instruction on this page worked. Hope it helps someone. The key is you need to mount to get writing permission in the device via adb.

Community
  • 1
  • 1
sivi
  • 10,654
  • 2
  • 52
  • 51