What is the equivalent of the spool command in MySQL?

时光怂恿深爱的人放手 提交于 2019-11-27 08:22:08

问题


I know you use the spool command when you are trying to write a report to a file in Oracle SQLplus.

What is the equivalent command in MySQL?

This is my code:

set termout off

spool ${DB_ADMIN_HOME}/data/Datareport.log @ ${DB_ADMIN_HOME}/Scripts.Datavalidation/Datareportscript.sql

spool off
exit

How can I write it in MySQL?


回答1:


If I get what you are asking:

mysql dbname < ${DB_ADMIN_HOME}/Scripts.Datavalidation/Datareportscript.sql \
> ${DB_ADMIN_HOME}/data/Datareport.log 

Use redirection.




回答2:


In MySQL you need to use the commands tee & notee:

tee data.txt;
//SQL sentences...
notee;

teedata.txt == spooldata.txt

notee == spool off




回答3:


For the Oracle SQLPlus spool command, there is no equivalent in the mysql command line client.

To get output from the mysql command line client saved to a file, you can have the operating system redirect the output to a file, rather than to the display.

In Unix, you use the > symbol on the command line. (It seems a bit redundant here to give an example of how to redirect output.)

date > /tmp/foo.txt

That > symbol is basically telling the shell to take what is written to the STDOUT handle and redirect that to the named file (overwriting the file if it exists) if you have privileges.


Q: is set pagesize and set linesize used in mysql when you are trying to generate a report?

A: No. Those are specific to Oracle SQLPlus. I don't know of any equivalent functionality in the mysql command line client. The mysql command line client has some powerful features when its run in interactive mode (e.g. pager and tee), but in non-interactive mode, it's an inadequate replacement for SQLPlus.



来源:https://stackoverflow.com/questions/11190337/what-is-the-equivalent-of-the-spool-command-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!