Create sqlite3 database at prompt
I tried using the following commands to create a database file at prompt, but none of them would work.
$ sqlite3 test.db
sqlite3 test.db
test.db
does it require a semi-colon at the end or is it that hard to create a database file using sqlite3 prompt?
Edit:
When I start the sqlite3 prompt, I get
SQLite versi开发者_运维技巧on 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
when type "sqlite3 test.db" I get,
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 test.db
...>
where should be the test.db file on the disk?
If you want a blank .db file just use:
touch stuff.db
I think the problem may actually be that the file does not seem to get created on disk until after you perform such action such as CREATE TABLE.
my actions:
C:\path\to\sqlite3.exe test.db
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit
no file was created.
Then:
C:\path\to\sqlite3.exe test.db
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t1(t1key integer);
sqlite> .quit
File shows up!
For future readers, this is from SQLite.org website and works for me:
SQLite version 3.8.5 2014-05-29 12:36:14
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open ex1.db
sqlite>
The example above causes the database file named "ex1.db" to be opened and used, and created if it does not previously exist. You might want to use a full pathname to ensure that the file is in the directory that you think it is in. Use forward-slashes as the directory separator character. In other words use "c:/work/ex1.db", not "c:\work\ex1.db".
Visit http://www.sqlite.org/cli.html for more details.
Hope this will help..
- Go to command prompt
- type cd \ (press enter)
- cd sqlite (press enter)
- sqlite3 mydb.db(press enter)
- .databases(press enter)
That's strange, simply typing
sqlite3 test.db
Should create the sqlite database it does for me, does it show any errors?
When it use that command I get the following output
$ sqlite3 test.db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
Which is the sqlite command line interface
In response to your edit you need to type sqlite3 test.db from your command line not from inside the sqlite prompt.
When you type it in your command prompt it will create the database in the directory where you are working and open the sqlite command prompt.
I faced same issue and then I logged into command prompt with Run as Administrator privilege and the issue is gone. Hope this helps someone.
What you have is incorrect:
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 test.db
...>
In particular the line : sqlite> sqlite3 test.db. It also does not match your statement: when type "sqlite3 test.db" I get,.
The command should be as follows:
sqlite3 test.db
This will then give you the following output:
SQLite version 3.20.0 2017-08-01 13:24:15
Enter ".help" for usage hints.
sqlite>
After this, you can must type .databases which will show you the full path to your file and then type .quit to exit out of this prompt. If you don't do at least .database command the file does not get created.
The file will be created in the directory you entered the command.
This is clearly showns here: sqlite tutoriaspoint
Hope this helps.
You can create a SQLite database file using Linux: touch db_name.db
If you want to execute commands such as create table you have to open databse file
first using: .open db_name.db
I also observed the same.
When I type sqlite3 test.db
, I enter the sqlite3 prompt.
Then checked the databases using command .databases
. Yahooo!! It shows the test.db and also in the directory I can see the test.db file.
I think the db file is visible only after we do any operation in the new database file. (Not sure)
It sounds like your Environment Variables haven't been setup to use SQLite3. Now I'm not sure of your OS, but here's how to set it under WinXP:
- Start -> Right-click 'My Computer'
- Select 'Properties'
- Select the 'Advanced' tab
- Click 'Environment Variables'
- (Under 'System Variables') Select 'Path'
- Click 'Edit'
- (Under 'Variable Value') Go to the end of the line and enter the path to your sqlite3.exe (minus sqlite3.exe) For example: C:\bin\sqlite3\;
And that's it! But remember that each path under 'Variable Value' is separated by a semi-colon, so make sure there is one before your new path.
精彩评论