rwolst rwolst - 1 year ago 213
SQL Question

Running a Sqlite3 Script from Command Line

I am writing a shell script to scp a project and part of it involves transferring some important tables in my database.

I have the following stored in the file


.o MyTable1.sql;
.dump MyTable1;

.o MyTable2.sql;
.dump MyTable2;

.o MyTable3.sql;
.dump MyTable3;

And took a chance on

$ sqlite3 SQLTableTransfer

But this just opened the Sqlite3 shell. What is the correct way to run a script like this from the command line?

Answer Source

The parameter you give to the sqlite3 program is the database file name.

To execute commands from a file, you must redirect the input to that file:

$ sqlite3 mydatabase.db < SQLTableTransfer

or tell it to read from that file:

$ sqlite3 mydatabase.db ".read SQLTableTransfer"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download