从脚本运行mySQL查询

时间:2013-05-01 02:39:29

标签: mysql

对于我的数据库类,老师指派我们使用Oracle SQL来设计应用程序。因为我对mySQL有更多经验,所以他说我可以用它来代替。

我想让我的作业尽可能地与他的例子相似。他的例子包括一个文件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

有没有办法做一些simliar?

是一种编写调用外部查询并将所有数据输出到output.txt文件的查询的方法吗?

2 个答案:

答案 0 :(得分:1)

使用'source'输入* .sql文件

使用'create procedure'生成'drop'功能

使用“into outfile'/ file / path';”在你选择写出来。

双重重定向追加:“进入outfile”>> / file / path';“

答案 1 :(得分:0)

source命令行客户端的mysql命令可以在这里完成工作:

source start.sql;

DESC table_name;

您可以使用help获得更多命令。

相关问题