Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening database file from within SQLite command-line shell

Tags:

sqlite

I'm using the SQLite Command Line Shell. As documented, I can open a database by supplying it as an argument to the executable:

sqlite3 data.db 

I cannot figure out how to open a database file from within the tool after having invoked it without supplying the file as a command-line argument (if I, say, double-click sqlite3.exe in Windows).

What is the command within the SQLite shell tool to specify a database file?

like image 921
Nolan Amy Avatar asked Jan 29 '12 23:01

Nolan Amy


People also ask

How do I query a SQLite database from the command line?

Start the sqlite3 program by typing "sqlite3" at the command prompt, optionally followed by the name the file that holds the SQLite database (or ZIP archive). If the named file does not exist, a new database file with the given name will be created automatically.

How do I open a database in terminal?

To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.

How do I open a .DB file?

How to open a DB file. Many types of DB files are not meant to be opened by users. However, if your DB file is a SQLite database, you can open it and view the data it contains with SQLite Database Browser.


2 Answers

You can attach one and even more databases and work with it in the same way like using sqlite dbname.db

sqlite3 : sqlite> attach "mydb.sqlite" as db1; 

and u can see all attached databases with .databases

where in normal way the main is used for the command-line db

.databases seq  name             file                                                       ---  ---------------  ---------------------------------------------------------- 0    main                                                                        1    temp                                                                        2    ttt              c:\home\user\gg.ite                                    
like image 177
ant Avatar answered Oct 04 '22 09:10

ant


I think the simplest way to just open a single database and start querying is:

sqlite> .open "test.db" sqlite> SELECT * FROM table_name ... ; 

Notice: This works only for versions 3.8.2+

like image 45
rindeal Avatar answered Oct 04 '22 10:10

rindeal