MySQL select into outfile /tmp 无输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1038170/
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 13:34:45  来源:igfitidea点击:

MySQL select into outfile /tmp no output

mysqlsqlinto-outfile

提问by Andy

I cannot get the following code to generate any output. The MySQL user has "all" grant level, /tmp is writable, the query returns a results set.

我无法获得以下代码来生成任何输出。MySQL 用户具有“全部”授予级别,/tmp 是可写的,查询返回一个结果集。

mysql> SELECT field FROM test_table WHERE condition='test'
    -> INTO OUTFILE '/tmp/test.csv'
    -> FIELDS TERMINATED BY ','
    -> ENCLOSED BY '"'
    -> LINES TERMINATED BY '\n';
Query OK, 1 row affected (0.00 sec)

mysql>
[1]+  Stopped                 mysql
[root@web1 ~]# cat /tmp/test.csv
cat: /tmp/test.csv: No such file or directory

Should I be seeing different output from MySQL in case of failure?

如果出现故障,我是否应该看到来自 MySQL 的不同输出?

Can I verify the result further than "1 row affected"?

除了“受影响的 1 行”之外,我可以进一步验证结果吗?

回答by Dipin

The files generate by the outfile clause are created on the mysql server host. Please make sure you are looking on the mysql server host as it seems you are on the client host which most likely isn't the mysql server host.

outfile 子句生成的文件是在 mysql 服务器主机上创建的。请确保您正在查看 mysql 服务器主机,因为您似乎在客户端主机上,而这很可能不是 mysql 服务器主机。

See http://dev.mysql.com/doc/refman/5.0/en/select.htmlin the section about outfile for documentation regarding this.

有关这方面的文档,请参阅有关 outfile 的部分中的http://dev.mysql.com/doc/refman/5.0/en/select.html

回答by Wu Yongzheng

I came across this problem in Fedora 17 and it was caused by systemd. I think it's good to share.

我在 Fedora 17 中遇到了这个问题,它是由 systemd 引起的。我觉得很好分享。

mysql> select * into outfile '/tmp/z1' from t1;
Query OK, 673 rows affected (0.01 sec)
mysql> select * into outfile '/tmp/z2' from t1;
Query OK, 673 rows affected (0.01 sec)
mysql> select * into outfile '/tmp/z1' from t1;
ERROR 1086 (HY000): File '/tmp/z1' already exists
mysql> Bye

# cat /tmp/z1
cat: /tmp/z1: No such file or directory
# ls -d systemd-*
/tmp/systemd-private-AQEueG
/tmp/systemd-private-AuCNDY
/tmp/systemd-private-TOMNxZ
/tmp/systemd-private-UacrpE
/tmp/systemd-private-yal7lQ
/tmp/systemd-private-ZlRJeN
# ls /tmp/systemd-private-TOMNxZ
z1  z2

The culprit was in /usr/lib/systemd/system/mysqld.service.

罪魁祸首在/usr/lib/systemd/system/mysqld.service。

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

Thanks to this blog, I found the clue.

感谢这个博客,我找到了线索。

回答by edwardsharp

Sounds like you might be running into a file permissions problem. Be sure that the user:group that mysqld is running under has adaqute permission to write to /tmp/test.csv

听起来您可能遇到了文件权限问题。确保运行 mysqld 的 user:group 具有写入 /tmp/test.csv 的 adaqute 权限

There's a whole variety of server daemon/file permission flavours that would solve the problem. Presumably UNIX-based, you could: chgrp mysqldGROUP /tmp

有各种各样的服务器守护程序/文件权限风格可以解决这个问题。大概是基于 UNIX 的,你可以: chgrp mysqldGROUP /tmp

But that makes it seem so easy- your server is configured in a certain way, so you adapt to that. The mysqld process should really only be able to read/write from a handful of places.

但这使它看起来如此简单 - 您的服务器以某种方式配置,因此您可以适应它。mysqld 进程应该真的只能从少数几个地方读/写。