I have .sql files which have the following content:
我有.sql文件,有以下内容:
#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?
如何将该文件导入到SQLite中,以便自动创建这些文件?
4 个解决方案
#1
118
From a sqlite prompt:
从一个sqlite提示:
sqlite> .read db.sql
Or:
或者:
cat db.sql | sqlite3 database.db
Also, your SQL is invalid - you need ;
on the end of your statements:
而且,您的SQL是无效的——您需要;在你的发言结束时:
create table server(name varchar(50),ipaddress varchar(15),id init);
create table client(name varchar(50),ipaddress varchar(15),id init);
#2
47
Use sqlite3 database.sqlite3 < db.sql
. You'll need to make sure that your files contain valid SQL for SQLite.
使用数据库sqlite3。sqlite3 < db.sql。您需要确保您的文件包含SQLite的有效SQL。
#3
8
You can also do:
你也可以做的事:
sqlite3 database.db -init dump.sql
#4
8
Alternatively, you can do this from a Windows commandline prompt/batch file:
或者,您可以从Windows命令行提示符/批处理文件中执行此操作:
sqlite3.exe DB.db ".read db.sql"
Where DB.db is the database file, and db.sql is the SQL file to run/import.
DB。db是数据库文件,db是数据库文件。sql是要运行/导入的sql文件。
#1
118
From a sqlite prompt:
从一个sqlite提示:
sqlite> .read db.sql
Or:
或者:
cat db.sql | sqlite3 database.db
Also, your SQL is invalid - you need ;
on the end of your statements:
而且,您的SQL是无效的——您需要;在你的发言结束时:
create table server(name varchar(50),ipaddress varchar(15),id init);
create table client(name varchar(50),ipaddress varchar(15),id init);
#2
47
Use sqlite3 database.sqlite3 < db.sql
. You'll need to make sure that your files contain valid SQL for SQLite.
使用数据库sqlite3。sqlite3 < db.sql。您需要确保您的文件包含SQLite的有效SQL。
#3
8
You can also do:
你也可以做的事:
sqlite3 database.db -init dump.sql
#4
8
Alternatively, you can do this from a Windows commandline prompt/batch file:
或者,您可以从Windows命令行提示符/批处理文件中执行此操作:
sqlite3.exe DB.db ".read db.sql"
Where DB.db is the database file, and db.sql is the SQL file to run/import.
DB。db是数据库文件,db是数据库文件。sql是要运行/导入的sql文件。