[英]Running mySQL queries from a script
For my database class the teacher assigned us to use Oracle SQL to design an application. 对于我的数据库课程,老师指定了我们使用Oracle SQL来设计应用程序。 Because I have more experience with mySQL he said I could use it instead.
因为我对mySQL有更多的经验,所以他说我可以改用它。
I want to make my assignment look as simliar to his example as possible. 我想让我的任务看起来尽可能类似于他的例子。 What his example consists of of is one file run.sql that looks like this:
他的示例包括一个文件run.sql,如下所示:
@start //this runs start.sql which creates the tables
DESC table_name; //do this for all tables
@insert //this runs insert.sql that creates dummy data
SELECT * FROM table_name; //do this for all tables
@query //this runs query.sql that runs our sample queries
@drop //this kills all the data
Is there a way to do something simliar? 有没有办法做类似的事情?
Namely a way to write a query that calls external queries and outputs all data to an output.txt file? 也就是说,编写查询的方法可以调用外部查询并将所有数据输出到output.txt文件?
Use 'source' to input the *.sql files 使用“源”输入* .sql文件
use 'create procedure' to generate the 'drop' function 使用“创建过程”生成“放置”功能
use "into outfile '/file/path';" 使用“到outfile'/文件/路径';” on your select to write out.
根据您的选择写出来。
double redirect to append: "into outfile '>>/file/path';" 双重重定向以追加:“入outfile'>> / file / path';”
The source
command for the mysql
command-line client could do the job here: mysql
命令行客户端的source
命令可以在此处完成此工作:
source start.sql;
DESC table_name;
You can get more commands with help
. 您可以在
help
获得更多命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.