从命令行运行脚本SQLITE3 [英] Running a Sqlite3 Script from Command Line

查看:1398
本文介绍了从命令行运行脚本SQLITE3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个shell脚本涉及在我的数据库传递一些重要的表,SCP的项目的一部分。

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

我有以下存储在文件中 SQLTableTransfer

I have the following stored in the file SQLTableTransfer:

.o MyTable1.sql;
.dump MyTable1;

.o MyTable2.sql;
.dump MyTable2;

.o MyTable3.sql;
.dump MyTable3;

和花了一个机会上。

$ sqlite3 SQLTableTransfer

但是,这只是拉开了SQLite3的外壳。什么是从命令行运行脚本这样的正确方法?

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

推荐答案

你给的sqlite3 程序的参数是数据库文件名。

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"

这篇关于从命令行运行脚本SQLITE3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆