3

I am simply trying to create a database.

In my account's home directory, I type in

sqlite3 test.db

Then once I am in sqlite, I type

.quit

That should create the database file in the current directory. But there is no such file! I tried it in other directories (chmodded to 777) to no avail.

What am I doing wrong? OS is Ubuntu 14.04 LTS. Sqlite version 3.8.2.

3 Answers 3

5

It's because you haven't actually done anything.

Doing nothing:

phil@ironforge:~$ sqlite3 test.db
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit

File not created:

phil@ironforge:~$ ls -al test.db
ls: cannot access test.db: No such file or directory

Do something:

phil@ironforge:~$ sqlite3 test.db
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table a (b number);
sqlite> .quit

File has been created:

phil@ironforge:~$ ls -al test.db
-rw-r--r-- 1 phil phil 2048 Oct 21 09:31 test.db
phil@ironforge:~$
1
  • I've seen several tutorials that menioned the instructions in my original post. And I vaguely remember being able to successfully create empty databases in the past with this command. But your answer works - I have added a table and then removed it again to create a blank database.
    – reggie
    Commented Oct 21, 2015 at 9:08
3

You can create an empty database with

sqlite3 new.sqlite "SELECT 1;"

A database is created and the result of the SELECT is printed, leaving just an empty database.

0

you can just touch a database in GNU/LINUX families...

touch test.db

this would save time and you can open the database and edit it whenever you want. or read it's data from existing .sql file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.