Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite3 - how to list out database name using .databases command?

Tags:

sqlite

I'm a fresher of rails and SQLite.

Here is my scenario: I had sqlite3 installed on my Windows Vista machine. A blog application code had also been implemented at c:\rails\blog. I brought up my command prompt and went directly to c:\rails\blog\db. I ran the command sqlite3 to enter the database console. when I used the .databases command, no database was listed out? Why? What have I done wrong?

like image 648
Sarun Sermsuwan Avatar asked Oct 09 '11 18:10

Sarun Sermsuwan


People also ask

How do I find my SQLite database name?

When using the SQLite command line interface, you can use the . databases command to return a list of attached databases. More specifically, it returns the names and file names/location of each attached database.

How do I list SQLite databases?

Show databases in the current database connection To show all databases in the current connection, you use the . databases command. The . databases command displays at least one database with the name: main .


2 Answers

You probably didn't open the database itself

sqlite3 database.db

Remember, that in SQLite a database is just a file. As long as you don't open or attach one, there is no open one. On the other hand when you just open the database .databases feels a kind of useless, because you know which one you just opened.

like image 172
KingCrunch Avatar answered Oct 19 '22 12:10

KingCrunch


You must provide the database (path and) name to the sqlite3 command, e.g.,

Dev e$ sqlite3 my_test.db
SQLite version 3.7.7 2011-06-23 19:49:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .databases
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /Users/e/Dev/my_test.db                                   
sqlite> 
like image 45
Doug Currie Avatar answered Oct 19 '22 11:10

Doug Currie