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?
Solution 1
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.
Solution 2
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
Solution 3
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.
Solution 4
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>
Solution 5
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
Related videos on Youtube
Julian A.
Updated on July 09, 2022Comments
-
Julian A. almost 2 years
# sqlite3 /data/data/com.moodme.android/databases/moodme sqlite3 /data/data/com.moodme.android/databases/moodme sqlite3: not found
-
whoopdedoo about 4 yearsanother relevant answer stackoverflow.com/a/60892396/2655092
-
-
Nathan Schwermann over 13 yearsIf you install cyanogenmod it has sqlite3 working in the shell.
-
Julian A. over 13 yearsBut 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?
-
CommonsWare over 13 years@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. -
Julian A. over 13 yearsAh. 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.
-
CommonsWare over 13 years@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.
-
Julian A. over 13 years@CommonsWare: Right on. Thanks.
-
michael about 13 yearsCan you please tell me where I can find sqlite3 for NexusOne on Gingerbread? Thank you.
-
Waza_Be over 12 yearsWould be grat if we could do that inside an application to fix the issue for our users!
-
Chris Blunt about 12 yearsWorks on rooted Nexus-S running Android ICS 4.0.4 using the sqlite3 binary from SuperOneClick (shortfuse.org/?page_id=2 / download.cnet.com/SuperOneClick/3000-2094_4-75447027.html)
-
Eugene van der Merwe over 11 yearsWorks on GT-i9100 4.03 ICS by pulling sqlite3 from emulator and then pushing up as instructed.
-
hugemeow over 11 yearswhere do you find that sqlite3 command build for your device? or you build it by yourself?
-
mrroboaat almost 11 yearsIt 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
-
user123321 over 10 yearsTo 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.
-
Lau Llobet over 10 yearsThis works on my nexus 4 with kitkat , sqlite3 binary got from the emulator /system/xbin folder
-
Fermat's Little Student about 10 yearsI got permission denied
-
Kazuki over 9 yearsand this is a link to SQLite SQLite version 3.8.6 2014-08-15 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)
-
dfinn about 9 yearsAlso 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.
-
Amit Thaper almost 9 yearsI got when using ./sqlite3 sh: ./sqlite3: not executable: magic 7F45
-
Andrew Smart over 8 years@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 over 8 years@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.
-
Weekend about 8 yearsTo 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. -
CommonsWare almost 6 years@IgorGanapolsky: There is no guarantee that a command-line
sqlite3
client binary will exist on any device.