将 MySQL 源结果输出到日志文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4146456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:42:17  来源:igfitidea点击:

Output MySQL source results to log file

mysqlsqlinto-outfile

提问by Isaac

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

我正在尝试使用 MySQL 中的 source 命令执行 foo.sql。

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?

现在,这个文件中有很多语句正在执行,我想回顾一下这些语句的成功/失败。有没有办法将语句的结果通过管道传输到日志文件 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.

但是,键入此命令似乎假定源语句之后的所有内容都是一个文件名;所以它试图将一个名为 '~/foo.sql 的文件导入到 outfile ~/foo.txt' 中,该文件显然不存在。

回答by Vlad the Impaler

From within your MySQL client, type

从您的 MySQL 客户端中,键入

tee session.out

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

从那时起,当前客户端会话中的所有 I/O 都将写入文件“session.out”

回答by Marc B

You could do it from the shell prompt:

您可以从 shell 提示符执行此操作:

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

回答by SorcyCat

Use the command line:

使用命令行:

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