I just started with sql using sqlite 3.7.17. I tried reading through here. As suggested I ran
create table test (id);
.quit
commands in sqlite terminal. No .db file was created in the current directory.
Then I tried to read through the documentation and ran
sqlite3 test.db
in the terminal. No .db file was created but sqlite terminal opened up. I ran
;
.quit
in the sqlite terminal and the .db file was created.
I am using Windows 7 and the terminal that I keep talking about is the Windows Powershell. I have placed the binaries for Windows in C:\Windows\system32\ folder so that the terminal recognizes sqlite3.
What did I do wrong? Why was .db file created once?
In the first case you probably ran sqlite3 without specifying a database file, so the program wouldn't know which file to create. In the second case you specified a file, but it isn't created before you're running an actual SQL statement against it (; is an empty SQL statement, but a statement nonetheless).
Related
I have installed confluence and postgres on synology nas using docker. Both run succesfully. Now I have to copy the data from a .sql file to the database that I have created in postgres.
How can I do this? I tried looking up different things but nothing helps.
regards
Use could use psql and let read commands from the file and execute this in your database. --file=? will do the trick.
I have downloaded Geonetwork and opened it with NetBeans IDE 8.0.2. In that project, there exists some SQL files. How can i run them or create database based on these files?
Edit:
I have done some more research, and all i need is to connect to H2 driver, but somehow, i can't. It shows me this:
Cannot establish a connection to jdbc:h2: using org.h2.Driver (IO Exception: "java.io.FileNotFoundException: C:\Program Files\NetBeans 8.0.2\ .lock.db (The filename, directory name, or volume label syntax is incorrect)"; "C:\Program Files\NetBeans 8.0.2\ .lock.db" [90031-152]). So, how to fix this?
Go thru this document and you will have your database, Derby will give you a quick setup for your need.
NetBeans - Working with the Java DB (Derby) Database
Just remember to open your geonetwork sql files, from the file browser navigate to the location of the saved sql file and click open...
If you have other database already installed, such as MySQL, Oracle etc. You can check the documentation here (see database section)
I know that Mac OSx has pre-installed sqlite3.But when I am entering this command, when in
/usr/bin directory, sqlite3 test.db i get this displayed on terminal..
Adityas-MacBook-Air:bin adityabahuguna$ sqlite3 test.db
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
Its fine till now. But when i try to create a table by
sqlite> create table t(name text);
I always get this error:
Error: unable to open database "test.db": unable to open database file
This however does not occur when i directly use create table command without creating a new database. I want to figure out the way to create a new database (say test.db as above).
You're trying to create the database in /usr/bin where normal users don't have write access.
You can write to /usr/bin with root/sudo as suggested by Atul but that's not really something you should do.
Instead, specify a database path that is writable by your normal user, for example
sqlite3 ~/test.db
so the test.db gets created in your home directory.
you need to be logged in as root user to have create database privilege. you can become root user by following these steps: How to Become root user.
I'm designing a process to create a list of fuzzy duplicates for my colleagues. I have automated most of the process and have used a .bat file to open sqlite. However, I can now find no other way to read the code other than to manually type:
.read file_name.sql
Into command prompt. Is there a way I could type open and read the file from notepad with the commands prewritten, like a .bat file. For example:
cd sqlite -- enter directory with sqlite3 inside of it. DOS command
sqlite3 --to open the sqlite3 application DOS command
.read file_name.sql -- SQLite command
Thanks in advance, sorry if the question is trivial.
You can give a command as parameter to the sqlite3 tool:
sqlite3 mydatabasefile ".read file_name.sql"
You can find information on what you're looking to do with the SQLCMD tool. It allows SQL to be run from the command line.
I am using the EnterpriseDB pgAdmin III (v. 1.12.1) on a Windows 7, 32-bit machine to work with PostgreSQL databases on a remote Linux server. I am logged in as the user postgres, which allows me to access the $PGDATA directory (in this instance, it is found here: /var/lib/pgsql/data/)
If I log into the server via a terminal, run psql, and use the \copy command to import data from csv files into newly created tables, I have no problems.
If I'm in pgAdmin, however, I use the COPY command to import data from csv files into newly created tables.
COPY table_name FROM '/var/lib/pgsql/data/file.csv'
WITH DELIMITER AS ',' csv header
Sometimes this works fine, other times I get a permissions error:
ERROR: could not open file '/var/lib/pgsql/data/file.csv" for reading: Permission denied
SQL state: 42501
It is the inconsistency of the error that is confusing to me. When the error arises, I change the file permission to anywhere from 644 - 777, with no effect. I also try moving the file to other folders, e.g., var/tmp/, also with no effect.
Any ideas?
The problem is the access permissions trough the directories to the file. Postgres user does not have access to your home folder, for example. The answer is to use a folder all users have access like /tmp, or create one with the correct permissions so any user can access/read/write there, a sort of users shared folder.
I think your postgres user still don't have access to your file.
Did you tried the folowing commands ?
chown postgres /var/lib/pgsql/data/file.csv
chmod u+r /var/lib/pgsql/data/file.csv
Try \COPY table_name FROM '/var/lib/pgsql/data/file.csv'
WITH DELIMITER AS ',' csv header
Notice the backslash before copy, when you run it with back slash it runs with user permissions other wise it just runs as postmaster which in the documentation is deprecated for recent versions of pg :|, anyways this might probably do the trick for ya .