sqldatabasesqliteimportdbimport

How to import .sql files into SQLite3?


I have .sql files which 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 do I import this file into SQLite so that these are created automatically?


Solution

  • From a sqlite prompt:

    sqlite> .read db.sql
    

    Or:

    cat db.sql | sqlite3 database.db
    

    Also, your SQL is invalid - you need ; on 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);