Output MySQL source results to log file

被刻印的时光 ゝ 提交于 2020-12-27 08:33:18

问题


I am trying to execute foo.sql using the source command in MySQL.

When I type the command, the file is sourced accordingly:

mysql> source ~/foo.sql

Now, there are a lot of statements being executed in this file and I would like to review the success/failure of these statements. Is there a way I can pipe the results of the statements to a log file, foo.txt?

I am thinking something along the lines of:

mysql> source ~/foo.sql into outfile ~/foo.txt

However, typing this command appears to assume that everything following the source statement is one file name; so it is trying to source a file named '~/foo.sql into outfile ~/foo.txt', which obviously doesn't exist.


回答1:


From within your MySQL client, type

tee session.out

From that point on, all the I/O of in your current client session is written to the file 'session.out'




回答2:


You could do it from the shell prompt:

$ mysql -p dbname < foo.sql > foo.txt



回答3:


Use the command line:

mysql -p dbname < ~/foo.sql > ~/foo.txt


来源:https://stackoverflow.com/questions/4146456/output-mysql-source-results-to-log-file

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