How to import .sql files in SQLite 3?

I have .sql files that have the following content:

#cat db.sql create table server(name varchar(50),ipaddress varchar(15),id init) create table client(name varchar(50),ipaddress varchar(15),id init) 

How to import this file into SQLite so that they are automatically created?

+61
sql sqlite
Jan 12 '10 at 13:10
source share
4 answers

From the sqlite prompt:

 sqlite> .read db.sql 

Or:

 cat db.sql | sqlite3 database.db 

Also, your SQL is invalid - you need to ; at the end of your statements:

 create table server(name varchar(50),ipaddress varchar(15),id init); create table client(name varchar(50),ipaddress varchar(15),id init); 
+107
Jan 12
source share

Use sqlite3 database.sqlite3 < db.sql . You need to make sure your files contain valid SQL for SQLite.

+41
Jan 12
source share

You can also do:

 sqlite3 database.db -init dump.sql 
+6
Jul 20 '15 at 15:22
source share

Alternatively, you can do this from the Windows command line command prompt / batch file:

 sqlite3.exe DB.db ".read db.sql" 

Where DB.db is the database file and db.sql is the SQL file to run / import.

+4
Jun 04 '15 at 9:43 on
source share



All Articles