Can't get sqlite3 command to work in Git Bash

Hi,

I believe I followed all the instructions here (https://www.codecademy.com/paths/web-development/tracks/sql-for-web-development/modules/0edc04f29e40457c0444c9e950d3d1b5/articles/what-is-sqlite) correctly, including changing the file path to reflect the new version of sqlite. However, when I try to run “sqlite3 newdb.sqlite”, I get this error message:

winpty: error: cannot start ‘C:/Users/First Last/Desktop/Codecademy/sqlite-tools-win32-x86-3310100/sqlite-tools-win32-x86-3310100/sqlite3.exe newdb.sqlite’: %1 is not a valid Win32 application. (error 0xc1)

Does anyone have a clue what may have gone wrong?

@ajax0049860725,

Welcome to the forums!

Were you able to get SQLite to run initially using these instructions (obviously with your correct path instead of the path below)?

@el_cocodrilo

I am experiencing similar difficulties with SQL on the Git Bash platfom. I am receiving a sqlite> prompt (Image #1). However, I cannot seem to load the data table suggested in the demonstration. When I select after typing in the code, nothing happens (Image#2). Your help is appreciated.

Image #1

image #2

@rubentar,

It looks like you’ve already set up your alias for SQLite, so just like in image #1, you should just type sqlite3 followed by your database file name.

The command sqlite3 acs-1-year-2015.sqlite should do what you want.

1 Like

@el_cocodrilo Thank you - yes, I was able to get “winpty ./sqlite3.exe” to work. I’ve tried it again, and it still works. It’s whenever I try to use the alias that I run into the issues.

@ajax0049860725,

Okay, then the issue probably traces back to the alias you made.

Using Git Bash (or whichever bash emulator you are using) navigate to the directory with sqlite3.exe in it. It should look similar to rubentar’s first screenshot, with 3 different .exe files and probably the newdb.sqlite file that you created.

Now, enter these commands into your terminal, hitting enter after each one:

echo "alias sqlite3=\"winpty ${PWD}/sqlite3.exe\"" >> ~/.bashrc

source ~/.bashrc

So long as you are in the correct directory, this should properly set up the alias. Now, if you type the command sqlite3 it should open a similar prompt to the one you get when you say winpty ./sqlite3.exe

@el_cocodrilo I tried entering the two commands, but still get the same error when I type “sqlite3” in the terminal. When I open Git Bash and type “alias” the alias I get for sqlite3 is:

alias sqlite3=‘winpty /c/Users/First Last/Desktop/Codecademy/sqlite-tools-win32-x86-3310100/sqlite-tools-win32-x86-3310100/sqlite3.exe’

Does this look correct?

I am also getting an error when calling the alias
The error message I get is:

bash: syntax error near unexpected token `(’

Can somebody help with this?
bash

@arcpro14748

You are probably getting an error because of the spaces in your path. PWD won’t put the path in quotes, so you get a syntax error right there at the space before ‘(’.

You should be able to fix this by putting single quotes around ${PWD} like so:

echo "alias sqlite3=\"winpty '${PWD}'/sqlite3.exe\"" >> ~/.bashrc

@ajax0049860725,

It’s hard to troubleshoot your exact problem without seeing a screenshot or your exact commands & error messages. I can’t tell if First Last is your username, or if that is supposed to represent your username being your first and last name separated by a space. Either way, if you have any spaces in your path, try out the solution above as that would explain why you can run the program with winpty ./sqlite3.exe, but your alias won’t work. However, if that were the case I would have expected the error to occur at the space rather than saying:

If the above code doesn’t work and you don’t feel comfortable posting a screenshot of your terminal, you can always try using DB Browser for SQLite, which is an excellent way to explore SQLite databases.

@el_cocodrilo image

@ajax0049860725,

Did you try redoing the instructions for the alias, but with single quotes around ${PWD}?

echo "alias sqlite3=\"winpty '${PWD}'/sqlite3.exe\"" >> ~/.bashrc

source ~/.bashrc

1 Like

@el_cocodrilo That fixed it - thank you!

No problem! If you do anything else in Bash, just remember that file paths/names with spaces will need quotes around them.

Also, even though we got everything working for the CLI, I still recommend you check out DB Browser when you have a chance. It is great for quickly looking through databases, especially those with multiple tables.

Happy coding!

Thanks for this, that solved the problem.

thank you so much. I’ve been struggling with this for the last 24 hours (yes, I’m a real newbie newbie to this…). So thanks a lot !

I am having a similar problem in that my git bash will not run my sqlite3

I downloaded the sqlite files into downloads and unzipped them, and this is what I get when I enter the relevant commands into git bash:

----------- MINGW64 ~
cd ~/Downloads/sqlite-tools-win32-x86-3320300/sqlite-tools-win32-x86-3320300/ ----------- MINGW64 ~/Downloads/sqlite-tools-win32-x86-3320300/sqlite-tools-win32-x86-3320300 winpty ./sqlite3.exe

--------- MINGW64 ~/Downloads/sqlite-tools-win32-x86-3320300/sqlite-tools-win32-x86-3320300
$

And after that I cant type anything in the window. The same thing happens when I move the sqlite file to a different location: the git bash window freezes after I enter the winpty ./sqlite3.exe command. Could it be that winpty ./sqlite3.exe is a bad command with respect to sqlite-tools-win32-x86-3320300 as opposed to sqlite-tools-win32-x86-3200100?

@script5110274274, this shouldn’t be happening. It doesn’t matter which version of SQLite you downloaded, so long as everything is typed correctly. Do you think you could post a screenshot showing the commands you’re typing into git bash when it freezes?

@script5110274274 that is strange. You may want to try re-downloading SQLite and/or git bash and trying it again. It looks like your commands are correct and it works fine for me with version 3320300 using the same commands.

If you can’t get it working, you can always use DB Browser for SQLite (I linked to the instructions earlier in the thread), which will do all the same stuff without the command line.