在MySQL中找不到由outfile创建的文件 [英] Can't find the file created by outfile in MySQL

查看:400
本文介绍了在MySQL中找不到由outfile创建的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下查询来创建一个CSV文件

 选择电子邮件INTO OUTFILEmydata.csv$ b $ 
bb
bb

bb










$

但是我无法在任何地方找到mydata.csv文件,当我通过filezilla进行搜索时。



是否得到存储?



查询成功运行没有任何错误!任何帮助?

解决方案<例如,MySQL可能会将文件写入自己的数据目录,例如 / var / lib / mysql /< databasename> 使用完整的路径。

然而,它必须是一个可以被MySQL服务器守护进程运行的用户帐户写入的目录。因此,我经常使用 / tmp



指定要写入的路径,如下所示:

  INTO OUTFILE'/tmp/mydata.csv'

注意MySQL会把这个文件写在MySQL <服务器,而不是在您的客户机上。因此,远程连接将在远程服务器上创建输出文件。另请参阅 SELECT INTO OUTFILE local?以获取更多详细信息和解决方法。



Systemd& Linux

有关在运行的Linux系统上写入 / tmp systemd ::

原本发布这个版本几年后,我发现自己无法找到写入 / tmp 通过

  ... INTO OUTFILE'/tmp/outfile.csv'$ b使用 systemd 运行Fedora Linux的MariaDB 5.5服务器上的$ b  

。该目录和文件不是按照指定直接写入 /tmp/outfile.csv ,而是在 / tmp

  /tmp/systemd-mariadb.service-XXXXXXX/tmp/outfile.csv 

文件 outfile.csv 本身和 tmp / 子目录都创建了全局可写,systemd服务目录本身拥有700个权限,并且是root拥有的,需要 sudo 访问检索其中的文件。



而不是在MariaDB中指定绝对路径为 /tmp/outfile.csv 并将其相对地指定为 outfile.csv ,则该文件按预期写入MariaDB的当前所选数据库的数据目录。


I am using the following query to create a CSV file

SELECT email INTO OUTFILE "mydata.csv"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM users;

But i am unable to find the mydata.csv file anywhere when i am searching through filezilla.

Any idea where this file is getting stored?

The query runs successfully without any errors! Any Help?

解决方案

MySQL may be writing the file into its own data directory, like /var/lib/mysql/<databasename> for example. To specify the path, use a full path.

However, it must be a directory that is writable by the user account the MySQL server daemon is running under. For that reason, I'll often use /tmp:

Specify the path you want to write to as in:

INTO OUTFILE '/tmp/mydata.csv'

And note that MySQL will write the file on the MySQL server, not on your client machine. Therefore remote connections will create output files on the remote server. See also SELECT INTO OUTFILE local ? for more details and workarounds.

Systemd & Linux

A note about writing to /tmp on a Linux system running systemd:

Some years after originally posting this, I found myself unable to locate a file written to /tmp via

...INTO OUTFILE '/tmp/outfile.csv'

on a MariaDB 5.5 server running Fedora Linux with systemd. Instead of writing the file directly to /tmp/outfile.csv as specified, that directory and file were created beneath a systemd directory in /tmp:

/tmp/systemd-mariadb.service-XXXXXXX/tmp/outfile.csv

While the file outfile.csv itself and the tmp/ subdirectory were both created world-writable, the systemd service directory itself has 700 permissions and is root-owned, requiring sudo access to retrieve the file within it.

Rather than specifying the absolute path in MariaDB as /tmp/outfile.csv and specifying it relatively as outfile.csv, the file was written as expected into MariaDB's data directory for the currently selected database.

这篇关于在MySQL中找不到由outfile创建的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆